Sure. But the DLL is now compiled on VS2008. Reading about safearrays and thinking about your suggest, I've find an assembly named system.visualstudio.ole.interop on VS2008 help that implements Safearray struct. I'll try to use it, but from now, I can't load the assembly. It doesn't appear on Net list references, but it is present on Windows\assembly. If I achieve to load it, I tell you about. Regards.
edmonson
Posts
-
Calling from VB.net to a Dll Win32 function that uses safearray pointer -
Calling from VB.net to a Dll Win32 function that uses safearray pointerMay be logic, but calling DLL from VB6 no safearray creation is needed. I will continue investigating. If I find a solution, I tell you. Regards.
-
Calling from VB.net to a Dll Win32 function that uses safearray pointerNo good result. The translated code to VB is:
Dim CBLeds(4) As CBTipo
CBLeds(0).Borna = 0 CBLeds(0).Carta = 0 Dim handleArray(4) As GCHandle For i As Integer = 0 To CBLeds.Length - 1 handleArray(i) = GCHandle.Alloc(CBLeds(i), GCHandleType.Pinned) Next i Dim pointers() As IntPtr = (From handle As GCHandle In handleArray Select handle.AddrOfPinnedObject()).ToArray() Dim ret As Integer = EncenderLEDs(pointers, False) ' Release the handlesforeach (GCHandle handle in handleArray) handle.Free(); For Each handle As GCHandle In handleArray handle.Free() Next
When I Call the DLL function, the process operates normally (no exception appears) but DLL function not executes correctly. Below you can see the code at EncenderLeds function. I'm getting the Ubound and Lbound of array to verify that this is passed good. The return of SafeArrayGetLBound is DISP_E_BADINDEX 8002000B The return of SafeArrayGetUBound is DISP_E_BADINDEX 8002000B So execution is failed.
NOMANGLE short CCONV EncenderLEDs(LPSAFEARRAY *CBLeds, bool Estado)
{
CBTipo HUGEP *Leds;
long LBound, UBound;
//USHORT MatLeds[128];
//DWORD ReceivedBytes;
DWORD BytesWritten;
DATA Adat[256];
short ActAdat=0;
short nLed;
int j;
USHORT ErrorCnt;
char Cadena[200];for(unsigned char i=0;i<128;++i) { Adat\[i\].Address = 0; Adat\[i\].Data = 0; Adat\[128+i\].Address = 0; Adat\[128+i\].Data = 0; } int k,l; k=SafeArrayGetLBound(\*CBLeds,1,&LBound); l=SafeArrayGetUBound(\*CBLeds,1,&UBound); sprintf(Cadena,"Valores %x %x %d %d",k,l,LBound,UBound); MessageBox(NULL,Cadena,"Titol",0); return 0;
}
Any Idea what is happen?
-
Calling from VB.net to a Dll Win32 function that uses safearray pointerHi, I'am updating and old VB6 project to VB.net 2008. My old project uses a Win32 Dll and TLB file to shared types. From VB6 a reference is created to TLB file and interop works fine. From VB.net I can import TLB file successfully and types are accessibles, but not the functions. Using 'Declare Function' sentences to import DLL methods, I can access to DLL functions. My Win32 DLL has methods that uses LPSAFEARRAY pointer as input parameters. This is the declaration of one of this functions on DLL:
extern NOMANGLE short CCONV EncenderLEDs(LPSAFEARRAY *CBLeds, bool Estado);
To reference this from VB.net I write
Public Declare Function EncenderLEDs Lib "MonAuto.dll" (<MarshalAs(UnmanagedType.SafeArray)> ByRef CBLeds() As CBTipo, ByVal Estado As Boolean) As Integer
CBTIPO is defined on DLL as:
typedef struct{
short Carta;
short Borna;
} CBTipo;The type is correctly visible at VB.net after TLB is imported. I test the function with next code:
Dim CBLeds() as CBTipo
Redim CBLeds(4)
CBLeds(0).Borna = 0
CBLeds(0).Carta = 0
EncenderLEDs(CBLeds, False)An exception is reported: (Exception of HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND)) But if I use any single Type to create the array: Int32, Double, Single, byte, ... and modify the declaration function definition on Vb.net like:
Public Declare Function EncenderLEDs Lib "MonAuto.dll" (<MarshalAs(UnmanagedType.SafeArray)> ByRef CBLeds() As Integer, ByVal Estado As Boolean) As Integer
and modify the test in the same way: <pre>Dim CBLeds() as Integer Redim CBLeds(4) CBLeds(0).Borna = 0 CBLeds(0).Carta = 0 EncenderLEDs(CBLeds, False)</pre> Then the call is processed good. The question is, How must be defined a DLL Win32 function on VB.net that uses a LPSAFEARRAY * as input parameter, to send a userdefined type array ? I've tried:
Public Declare Function EncenderLEDs Lib "MonAuto.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_USERDEFINED)> ByRef CBLeds() As CBTipo, ByVal Estado As Boolean) As Integer
and fails too. Regards in advance
-
Disconnecting from SqlServer Database from VB.netYes, every time I attached again (without exiting from application) and try to get data, the problem appears. But if I restart application and reattach then works fine ! (Strange behavior:-() If I find the solution I'll report it.
-
Disconnecting from SqlServer Database from VB.netSorry, the message was: Sure, your code works and the database is deatached succesful! but when I execute an attach again(the same database): - Database is attached successful (I can see on Management Studio) - I open a connection an it opens succesful. - But when I call an cmd.ExecuteReader to get data, then next error message appears: "Error at level transport when send the query to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe)" I've reviewed SQL configuration, and all seems good. If I restart the App all work succesful. Any idea about it ?
-
Disconnecting from SqlServer Database from VB.netSure, this code works and the database is deatached succesful! but when I execute an attach again: - Database is attached successful (I can see on Management Studio) - I open a connection an it opens succesful. - But when I call an cmd.ExecuteReader to get data, then next error message appears: "Error at level transport when send the query to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe)" I've reviewed SQL configuration, and all seems good. If I restart the App all work succesful. Any idea, why the server process stopped ??
-
Disconnecting from SqlServer Database from VB.netI've tested from Management Studio and it works properly. From my application, the problem continues. When I execute ALTER DATABASE... the DB enters in Single User Mode (An icon appears on Db List in Mabagement Studio, but when execute detach it fails reporting that Database is in use :(
-
Disconnecting from SqlServer Database from VB.netThe connection to the app database is:
"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=work;Data Source=pcjordi2009\sqlexpress"
And when I connect to detach/attach I use:
"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Master;Data Source=pcjordi2009\sqlexpress"
-
Disconnecting from SqlServer Database from VB.netHello, I'am developing an App that needs to access a SqlDataBase named "Work", but this may be located in any drive of my system (C:,D:,U:,...). The database structure is always the same, so I use a unique name and only change the files. When the application start, I use a OpenFileDialog to locate the database and execute an storedprocedure to attach the database to SqlServer (EXEC sp_attach_db @dbname ...). This works fine, and I can work with the database. When the user ends to work with database, I want to detach ("EXEC sp_detach_db) this from my App to allow to choose another location one. At this point I get an error reporting that the database is currently in use, ans so, it can't be detached. StoredProcedures form attach and detach owns to Master database, so when I execute it I'am not using my database. Do you know any procedure to disconnect my App from database using system.data, and then I could execute the detach procedure ? (If I only execute Attach and Detach, without accessing to database, is runs fine). Here the Detach function:
Public Function DetachDB(ByVal DbName As String) As Boolean
Dim Cmd As New SqlClient.SqlCommand
Dim AffectedRows As Int32
Dim TmpDbName As String = _DbName
_DbName = "Master"
Cmd.Connection = GetConnection
Cmd.CommandText = "EXEC sp_detach_db @dbname = '" & DbName & "'"
Cmd.CommandType = CommandType.Text
Cmd.Connection.Open()
Try
AffectedRows = Cmd.ExecuteNonQuery()
Cmd.Connection.Close()
_DbName = TmpDbName
Return (True)
Catch e As Exception
If PopupErrors Then
MessageBox.Show("[DB]Error separando la base de datos " + e.Message)
End If
Cmd.Connection.Close()
_DbName = TmpDbName
Return False
Exit Function
End Try
End Function -
Redirect a printing job to another printerSupose I have default windows printer always in Pause because I want to control jobs send by users. Using system.printing I detect jobs and I want to decide if this may be printed or not. If I decide to print I want to send the job to another on-line printer. Is possible to change a job in default printer queue to another printer queue ? The job depends on printer and the on-line printer must use the same driver or the printer may be different ?
-
Catch printing any document from any application (word, excel, pdf,...) to show printing optionsHi, I'm developing a cybercafe app. and i need to detect printing process from other aplications(Word,Acrobat,...) I need to send the job to any printer and select if it may be in color or BW. User doesn't use printer properties directly from its application(word,excel,...). He clicks on printing button directly. My trouble is catch this action to force him to show the destination printer and job color mode. I've been working with system.printing namespace to control the spooler: - When a new job arrives, I stop it. I obtain information about pages, printer,... but if I change any parameters like coloroutput property, it has no efect on the job when I resume it to finish the printing process (restart the job fails too) Any Idea ? Regards
-
Problem Localhost Web Reference method (fails showing return type)I build a minimal dataset: Dim Ds as new DataSet Ds.Tables.Add(MyTable) return(Ds) Thanks for your patient.
-
Problem Localhost Web Reference method (fails showing return type)Using DataSet and not DataTable as method argument and/or return type, the client application recognizes de types, and so it works. I've looking other forums, and other people has the same problem. Solution has not been found, but everybody is using DataSet vs. DataTable. Microsoft exposes this article, recommendating using DataSets: http://support.microsoft.com/kb/306134
-
Problem Localhost Web Reference method (fails showing return type)Hello again, Next description is more aproximated about problem is: I created a Web Service using .Net 2.0 that has a function that returns a DataTable. I can test the function from the web page when I access the .asmx from a browser on localhost and it works. The problem I have now is when using VS 2005 or VB.Net 2005 Express and creating a web references is that the proxy created doesn't map the function as returning a DataTable instead returns some other type of object named xxxxResult where xxxx is the name of the web service function. I have another function that returns a DataSet that works perfectly with the web reference although I'd rather use a DataTable since I won't need all the functionality that a DataSet brings. Anyone have the same problem and found a solution?
-
Problem Localhost Web Reference method (fails showing return type)Hi ! I have an object named RemoteDb that is implemented as a web service. It has a method named RemoteSql than accepts an input string and returns a system.data.datatable with the results. I've been working for a few days referencing it from VB and all works fine. This morning I have done some modifications to webservice and so, i have rebuilt it. From explorer, it continues working fine, but when I've updated the web reference from my applicaction (Vb.net IDE), this error has appeared: Value of type 'RegantsAlgerri.WebReference.RemoteSqlResponseRemoteSqlResult' can not be converted to 'System.Data.DataTable'. When i call the webmethod RemoteSql() .net environment explains me that return parameter is RegantsAlgerri.WebReference.RemoteSqlResponseRemoteSqlResult. In previous version (before update Web Reference) .net environment tells me that return type was System.Data.DataTable. Why reference is loaded with this bad return type ? Regards in advance
-
Property attribute setting using password char ??Using a propertygrid control i show my object properties to set and get. Using attribute properties like i show below, i can control Category, Description, even particular selection mode using TypeConverter() attribute.
<> _ Public Property IntercambioIn() ...
I need to read a password string, and i can't show password chars like '*'. Does exist any attribute to show the setting using password char ('*'). Regards -
Class process fails running from network drive ??Thank's for the answer. But, What must i do to make my assembly full trusted ? Sorry for my inexperience with security policies.
-
Class process fails running from network drive ??I'm running my application from a network drive. My framework is configured to grant all_codes security permissions to Everithing. Applications running fine, including accessing local ports, system file,... but if i use the class process, framework tell me that security policies do not permit this operation. Below a code brief.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MyProcess = New Process 'This line is security policy violation? MyProcess.StartInfo.UseShellExecute = False MyProcess.StartInfo.CreateNoWindow = True MyProcess.StartInfo.RedirectStandardOutput = True ...
How can i solve ? -
How to run a DOS process and get ErrorLevelI need to run a DOS process application and get the final ErrorLevel. Three questions: a) How can i execute from Vb.net a) How can i get the final ErrorLevel. b) Is possible to redirect output stream data process to a form on my applicacion. regards