473,499 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IJW - How exactly?

(I apologize if this is a fairly trivial question, but I mostly use
C#, not MC++.)

Problem: I've got an unmanaged DLL (and the LIB file), that exports a
bunch of static functions. I'd like to be able to wrap this with a
__gc class, and then access it from C#. All of the examples I've seen
are based upon wrapping unmanaged code (H and CPP files), not existing
DLLs. I'm sure I'm missing something.

Thanks,
Austin Ehlers
Nov 17 '05 #1
3 5354
Austin Ehlers <th***********************@hotmail.com> wrote in message
news:di********************************@4ax.com...
(I apologize if this is a fairly trivial question, but I mostly use
C#, not MC++.)
We won't hold that against you. :-)
Problem: I've got an unmanaged DLL (and the LIB file), that exports a
bunch of static functions. I'd like to be able to wrap this with a
__gc class, and then access it from C#. All of the examples I've seen
are based upon wrapping unmanaged code (H and CPP files), not existing
DLLs. I'm sure I'm missing something.


Well, I'll explain a couple of ways to attack the problem in the way you
suggest in a moment. But if all you want to do is to call unmanaged code in
a DLL from C# then there may be an easier way. Take a look at this:

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Back to what you asked:

Of the MS .Net compilers, MC++ stands alone in its ability to compile both
managed and unmanaged code segments in the _same_ module. You delimit those
segments with

#pragma managed

and

#pragma unmanaged

In an unmanaged segment you call DLL exported functions in the usual way.
IJW handles the transitions between managed and unmanaged code invisibly.
So, managed code in a method of a _gc class can call into an unmanaged code
segment which calls a DLL function.

Alternatively, you can use the [DllImport] attribute to declare an external,
static function that resides in a DLL. In most cases, the compiler will
marshall the arguments and make the call without extra work on your part.

Regards,
Will

Nov 17 '05 #2
On Thu, 1 Jan 2004 19:37:56 -0500, "William DePalo" <wi***@mvps.org>
wrote:
Austin Ehlers <th***********************@hotmail.com> wrote in message
news:di********************************@4ax.com.. .
(I apologize if this is a fairly trivial question, but I mostly use
C#, not MC++.)
We won't hold that against you. :-)


Thanks :)
In an unmanaged segment you call DLL exported functions in the usual way.
IJW handles the transitions between managed and unmanaged code invisibly.
So, managed code in a method of a _gc class can call into an unmanaged code
segment which calls a DLL function.


There's my problem. I don't know how to call the DLL functions. Take
this definition:

my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
and the C# definition of it is:

[ DllImport( "libmySQL.dll", EntryPoint="mysql_affected_rows" )]
unsafe public static extern ulong mysql_affected_rows(IntPtr mysql);

which works. I'm thinking something like:

extern "C"
{
UInt64 mysql_affected_rows(IntPtr mysql);
}
but how do I make it reference the DLL?

Thanks,
Austin Ehlers


Nov 17 '05 #3
Austin Ehlers wrote:
There's my problem. I don't know how to call the DLL functions. Take
this definition:

my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
and the C# definition of it is:

[ DllImport( "libmySQL.dll", EntryPoint="mysql_affected_rows" )]
unsafe public static extern ulong mysql_affected_rows(IntPtr mysql);

which works. I'm thinking something like:

extern "C"
{
UInt64 mysql_affected_rows(IntPtr mysql);
}
but how do I make it reference the DLL?


Just add the import library (libmySQL.lib) to your project. It defines
stub functions for the DLL that you can link into your project to
satisfy the extern declaration.

Jesse
Nov 17 '05 #4

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

Similar topics

14
2581
by: mjkahn | last post by:
I've read (and read!) that you shouldn't store objects in Session variables. I've read these reasons: - The object takes up memory that may not be freed until the session times out. Better to...
4
33326
by: cayblood | last post by:
Hello, I have the following class declaration in an include file: class Node { public: Node(string name = ""); Node(const Node& node); Node& operator=(const Node& node); bool...
22
2960
by: Fred Ma | last post by:
I'm using the expression "int a = ceil( SomeDouble )". The man page says that ceil returns the smallest integer that is not less than SomeDouble, represented as a double. However, my...
16
2637
by: thenightfly | last post by:
Ok, I know all about how binary numbers translate into text characters. My question is what exactly IS a text character? Is it a bitmap?
1
1886
by: TJ | last post by:
Dear Sir/Madam I made one user control using C#(.NET Runtime is 1.1). It is embeded in Internet Explorer Basically, this control is very similiar to FTP client program. So it should be connecte...
5
4103
by: Martin Jørgensen | last post by:
Hi, Consider this code: --- beginning of code --- #include <iostream> using namespace std; class Child{ public:
2
3348
by: Matthew Wilson | last post by:
The random.jumpahead documentation says this: Changed in version 2.3: Instead of jumping to a specific state, n steps ahead, jumpahead(n) jumps to another state likely to be separated by many...
19
3561
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
28
5802
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
7
4387
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
0
7007
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
7171
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,...
1
6893
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
5468
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,...
1
4918
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
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.