473,549 Members | 2,751 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 4420
In article <11************ *********@f14g2 000cwb.googlegr oups.com>, ma*****@yahoo.c om 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.Str ingBuilder. 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.d ll" Alias "GetUserNam eA" _
(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.d ll" _
(ByVal lpBuffer As System.Text.Str ingBuilder, _
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
6967
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 MSDN docs, SendInput appears to take an array of inputs:
15
4441
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 application runs flawlessly, but once I call the class from inside a c# windows application the program freezes, crashes etc... there must be a way...
9
4950
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 the PPC is located in coredll.dll and on the desktop in kernel32.dll. I could make two versions of the DllImported funktions but then I would have to...
4
11927
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 lpBuffer As String, nSize As Long) As Long How do I translate to C#? thanks!
3
3451
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 have the same signature, and I never have to call more than one DLL in the same program. (The DLLs parse and validate 5 different binary formats.)...
9
4799
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 array. Now, I can call it like this: byte* lpBuffer; int length; string subBlock = @"\StringFileInfo\" + langCodePage + @"\FileDescription"; result =...
12
1617
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 Function Tick() As Integer
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 converted in the declaration. Is there any doco somewhere that identifies what needs to be changed in the Declare statement ? i.e. long =...
4
7593
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 desiredAccess, UInt32 shareMode,
0
7524
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7960
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6048
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5372
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5089
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.