473,503 Members | 12,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c++ dll declare dllimport

I'm trying to call methods in a C++ dll from vb.net that is not a .com
component. I've read I can just use regular Declare statements just as

you do in VB6 except that some of the types need to be converted in the

declaration.
Is there any doco somewhere that identifies what needs to be changed in

hte Declare statement ? i.e. long = integer, etc...
Also, I'm having to build the declare statements based on some doco I
have from the DLL. Is there a tool or something that will build the
declare statements for me ?
Ok, one more thing. Some of these methods in the DLL return strings
that were passed by reference as an argument. Is there anything I
should be look out for when using strings, either passed as arguments
by reference and modified in the DLL or just returned from the function

? Seems like I've read somewhere the former that can be a problem.
Many TIA,
Mark

Nov 21 '05 #1
1 4401
In article <11*********************@f14g2000cwb.googlegroups. com>, ma*****@yahoo.com wrote:
I'm trying to call methods in a C++ dll from vb.net that is not a .com
component. I've read I can just use regular Declare statements just as

you do in VB6 except that some of the types need to be converted in the

declaration.
Is there any doco somewhere that identifies what needs to be changed in

hte Declare statement ? i.e. long = integer, etc...
Also, I'm having to build the declare statements based on some doco I
have from the DLL. Is there a tool or something that will build the
declare statements for me ?
Ok, one more thing. Some of these methods in the DLL return strings
that were passed by reference as an argument. Is there anything I
should be look out for when using strings, either passed as arguments
by reference and modified in the DLL or just returned from the function

? Seems like I've read somewhere the former that can be a problem.
Many TIA,
Mark


The best advice I can give you here is to read the documentation on
platform invoke and marshalling. Here is a good place to start:

http://msdn.microsoft.com/library/de...formInvoke.asp

Unfortunately, most of the example code is C# - but the concepts are
aplicable to VB.NET as well.

The do have a table in there that lists a lot of the common datatype
conversions. But, for the most part, its the same as in VB.CLASSIC -
you pick the type that has the same corresponding size.

C VB.NET
char Byte
short Short
int Integer
long Integer

Handle types, should usually be declared as IntPtr and any 64-bit values
should be Long.

Strings are a little different... If string is being passed as an out
parameter - it is being modified by the called procedure, then it really
should be declared as ByVal ParamName As System.Text.StringBuilder. If
it is a constant string, then ByVal ParamName As String is fine. String
will work for out params as well, but it results in a lot of extra work
for the VB.NET marshaller since .NET strings are immutable. Also, you
should be aware that VB.NET, unlike VB.CLASSIC, is able to directly
access Unicode functions via declare statements. In VB.CLASSIC the only
way to do it was by using StrPtr or using a typelibrary wrapper for the
function. The result of this is that in VB.CLASSIC you would often see
such declarations as:

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
In VB.NET, you would remove the alias and change the data types
somewhat...

Declare Auto Function GetUserName Lib "advapi32.dll" _
(ByVal lpBuffer As System.Text.StringBuilder, _
ByRef nSize As Integer) As Boolean
Anway, reading through the docs, experimenting, and then posting questions
to the groups - probably the interop group would be the most appropriate -
are really the best ways to learn this stuff...

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 1 Days, 0 Hours, 1 Minutes, 32 Seconds
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6959
by: Richard A. Lowe | last post by:
I'm successfully using SendInput to emulate mouse events for a legacy app, delcared like so: public extern static int SendInput( int theCount, ref INPUT pInputs, int theSize ); From the...
15
4435
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
9
4946
by: Ole Christensen | last post by:
I'm trying to make a sort of conditional compilation in my C# code because my app is intended to run on both a Pocket PC and on a normal desktop PC. My code uses a call to an API function that on...
4
11922
by: cloudx | last post by:
Hi there, I would like to retrieve the computer name in C#, here is the piece of code in VB: Private Declare Function GetComputerNameAPI Lib "kernel32" Alias "GetComputerNameA" (ByVal...
3
3446
by: Mark Jerde | last post by:
I'm sill learning VS .NET 2003, not an expert yet. I'm calling an unmanaged C++ DLL from C# using . When the whole project is done I will be calling a total of 5 C++ DLLs from C#. All the DLLs...
9
4793
by: Dave | last post by:
I am trying to call VerQueryValue from a C# program. VerQueryValue takes as one of its parameters a pointer to a pointer to an array of bytes, which it uses to return a pointer to the required...
12
1608
by: M. Angelo | last post by:
If you don't know or are in doubt, please read the answers instead of showing your ignorance. This is not a newbie question. Anyone know how to do something like this: Private Delegate...
0
273
by: marfi95 | last post by:
I'm trying to call methods in a C++ dll from vb.net that is not a .com component. I've read I can just use regular Declare statements just as you do in VB6 except that some of the types need to be...
4
7581
by: =?Utf-8?B?UmljaGFyZEBub3NwYW0ubm9zcGFt?= | last post by:
I'm trying to declare CreateFile as an extern from the dll like so: .... using System.Runtime.InteropServices; internal static extern IntPtr CreateFile( String filename, UInt32...
0
7098
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...
0
7296
Oralloy
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,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.