|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
[Help] Reading data from a DLL structure in CVB.NET, can anyone help me to understand this? I am totally new to this API or MarshalA. Structure of the function: int GetDLLVersion(char *data, int datasize) the *data will return a 7 character word, but how can i store it into the variable of VB.NET? i tried this: Dim VerNum as String <DLLImport ("Vertx.dll")> Public Shared Function GetDLLVersion (ByRef VerNum as String, ByVal data as Integer) as Integer End Function GetDLLVersion(VerNum, 10) When ever i try to call this function, a error message prompt out which tell me the problem of object, so i replace the code with: Dim VerNum as Char <DLLImport ("Vertx.dll")> Public Shared Function GetDLLVersion (ByRef VerNum as Char, ByVal data as Integer) as Integer End Function GetDLLVersion(VerNum, 10) it work, but only one character was returned, since char type only store up to one character, this is not what i want, can somebody help me to deal with this problem? >Dim VerNum as String The string should be passed ByVal, and I believe it actually has to be><DLLImport ("Vertx.dll")> Public Shared Function GetDLLVersion (ByRef >VerNum as String, ByVal data as Integer) as Integer >End Function > >GetDLLVersion(VerNum, 10) big enough to hold the data before the call (ie at least 10 characters). You can also use a StringBuilder as the parameter type. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Ya, i had done some research in the net and i found that most ppl
provide 2 type of solution. One is using IntPtr to store the pointed address, the other one is use the string builder. Unfortunely, i cant get the full explanation on the usage of string builder, without any reference, it is very hard for me to figure out the way to use the string builder. Here is what i can get from net to change my code, please guide me to correct it. Thanks very much Imports System Imports System.Runtime.InteropServices Imports System.Text Inherits System.Windows.Forms.Form Public Ptr As IntPtr <MarshalAs(UnmanagedType.LPStr)> Public VerNum As String <DllImport("Vertx.dll")> Public Shared Function GetDLLVersion(ByVal VerNum As String, ByVal DataSize As Integer) As Integer End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GetDLLVersion(VerNum, 10) MsgBox(VerNum) End Sub This code return an error: "object Reference not set to an instance of object" how can i solve it?? Really need the help! >This code return an error: "object Reference not set to an instance of <DllImport("Vertx.dll")> Public Shared Function GetDLLVersion(ByVal>object" >how can i solve it?? VerNum As StringBuilder, ByVal DataSize As Integer) As Integer End Function .... Dim verNum As New StringBuilder(10) GetDLLVersion(VerNum, verNum.Capacity) MsgBox(VerNum.ToString()) Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
I miss loop
length of string Adding Button Programatically - have an answer??? Visual Studio 2003 Menu on form.vb best way to tell if a date is not assigned? Where is ThisWorkbook.Sheets("xx") ?? Unable to resolve 'ThisWorkbook' :: Interop to Excel Visual Basic .NET Resource Kit Form Size HTML code in textbox then string running balance in datagrid |
|||||||||||||||||||||||