I am trying to retrieve data from a function structured in C by using
VB.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? 3 2330
>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)
The string should be passed ByVal, and I believe it actually has to be
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 object" how can i solve it??
<DllImport("Vertx.dll")> Public Shared Function GetDLLVersion(ByVal
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: AKF |
last post by:
I am trying to use data structures to open a file (void
display_Stock_Item(Stock_Item si);) from a text file. I also need to
be able to write to the file and also to delete from the file using...
|
by: Roob |
last post by:
I am learning C# and was wandering if there is a straightforward way to read
a binary file created by C++. For example, I have a data structure as
follows:
typedef struct _data
time_t date;...
|
by: C++ Hell |
last post by:
Hey everyone just designing a quiz for school and managed to write the
code for the questions and answers thou i have to add scores and at the
end an overall score does anyone have any idea what to...
|
by: -D- |
last post by:
I'm taking my first stab at using xml, so please bear with my novice
questions and understanding of xml.
I'm trying to create an xml file that holds all my website navigation. If I
understand...
|
by: skumar434 |
last post by:
i need to store the data from a data base in to structure
.............the problem is like this ....suppose there is a data base
which stores the sequence no and item type etc ...but i need only...
|
by: Y2J |
last post by:
I am working through this book on C++ programming, the author is
speaking of using linked lists. He gave and example which I found
confusing to say the least. So I rewrote the example in a way that...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: Sam |
last post by:
Hi,
I have one table like :
MyTable {field1, field2, startdate, enddate}
I want to have the count of field1 between startdate and enddate, and
the count of field2 where field2 = 1 between...
|
by: Don |
last post by:
I'm using Access 2000. My database collects lots and lots of data. One
aspect of that is to collect dimensional data from multiple checks during
the day. The way I've done that is to have a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |