473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

InteropServices and Dll function entrypoint.

Hi
I have an GetObject() function in my "old" unmangaed C++ compiled DLL. I
need to call some function in this dll, so I use DllImport in my C#
application.

This is how I do it: (This code works)

[DllImport("ITSIOU.dll", EntryPoint="?GetObjectW@CIODriver@@SAPAV1@XZ",
CallingConvention=CallingConvention.Cdecl)]
static extern int GetObject();

public ITSIOServiceInterface()
{
// Call GetObject to initialize ITSIOu.DLL.
CIODriver = new IntPtr(GetObject());
// Check for success
if( CIODriver.ToInt32() == 0)
{
// Error. No IO subsystem ready
return;
}
}

The CallingConvention isn't nesecary in my case (the dll is compiled with
Cdecl). I thought default was StdCall, so why does it work without it ?

If I use EntryPoint="GetObjectW" or EntryPoint="GetObject" I get an
EntryPointNotFoundException.

So my question is:

1: Why can't I use a more friendly name like "GetObject" instead of
?GetObjectW@CIODriver@@SAPAV1@XZ. ? Any way of doing this ?
(Tried with "[DllImport("ITSIOU.dll", EntryPoint="GetObject",
CallingConvention=CallingConvention.Cdecl)]". No luck)

2: When using DllImport on other function, ex. CreateFile from kernel32.dll,
I can use "CreateFile" without using an "unfriendly" name as entry point.
Why is there no problem on other DLL's ? (And others I have tried ?)

Thomass

Nov 15 '05 #1
1 2077
Thomas,
The CallingConvention isn't nesecary in my case (the dll is compiled with
Cdecl). I thought default was StdCall, so why does it work without it ?
There's no difference between the two when you don't have any
parameters.

1: Why can't I use a more friendly name like "GetObject" instead of
?GetObjectW@CIODriver@@SAPAV1@XZ. ? Any way of doing this ?
(Tried with "[DllImport("ITSIOU.dll", EntryPoint="GetObject",
CallingConvention=CallingConvention.Cdecl)]". No luck)
Because of the way the DLL was compiled and the function exported.
There's nothing you can do about that from the maanged side, you'd
have to rebuild the DLL if you want to change the name.

2: When using DllImport on other function, ex. CreateFile from kernel32.dll,
I can use "CreateFile" without using an "unfriendly" name as entry point.
Why is there no problem on other DLL's ? (And others I have tried ?)


The A and W suffix for Win32 APIs are such a common naming pattern
that the runtime has built in support for finding such functions even
if you don't explicitly provide the full name.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2

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

Similar topics

1
by: yaniv Abramovich | last post by:
Hi I'm trying to Pass pointer to a callback function from C# to C++ it's working ok for a few minuts and then it's stops. can anyone help with that ? public class PA_Client {
2
by: hykim | last post by:
I want to call a unmanaged dll's function returning some STRUCT's pointer. the next is definition of a STRUCT. ----------------------------------------------------------------------- typedef...
3
by: Wen | last post by:
hello, now, i wanna port a c++ program into C# project. a DLL written by C++ and keep it no change, and UI wirtten by C#. my C++ UI code is as below: // error handlers --global function...
2
by: Jason Bell | last post by:
I know this functionality already exists in .NET 2.0 via Marshal.GetDelegateForFunctionPointer, but I'd rather not force my users to use a beta framework (not to mention the fact that I'm still...
1
by: LongBow | last post by:
Hello, I am attempting to create an application that uses an existing driver interface API using C#. I have an API that looks like F32x_Read( HANDLE Handle, LPVOID Buffer, DWORD...
0
by: mjacu | last post by:
Hello I've got a problem using unmanaged dll in C++ on my website. I'm using System.Runtime.InteropServices namespace and DllImport. My dll allocate memory and generate some files using...
7
by: justin.kruger | last post by:
I am having a problem with exchanging handles with c# and the "CP210xManufacturing.dll" in a device wrapper that i am working on. I have created a wrapper class to address some of the functions...
3
by: Mike | last post by:
I have been banging my head againt my desk for a couple days now and nothing I try seems to work. I know I am missing something small and it's killing me. This is the error I am getting with...
2
by: Heike | last post by:
Hello everybody, I have a Problem with C Sharp. I have to use external functions in DLLs. This Functions are written in Visual C++ 6 like this: int (__stdcall *GetGlobalValue) (VARIANT Appl,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.