I need to call a Win32 DLL. The API supports both Windows and Linux, but
I'm only concerned with Windows. I'd like advice whether I can use C# or
whether I'll have to dust off my old C++ books. I would prefer to learn C#
rather than go back to C++.
The API starts with
#ifdef (WIN32)
#define MyAPI __stdcall
#else
#define MyAPI
#endif
There are bitmap mask #define statements.
All integer values are little-endian.
There are many "typedef" and "typedef struct" statements with char, const,
void, sint8, uint8, uint16, uint32, and sint32 elements, arrays and
pointers.
There are "typedef struct" statements with union elements.
To ease cross-platform use, the API defines its own memory management. This
is one typedef:
typedef void * (MyAPI *MyAPI_REALLOC)
(void * Memblock,
uint32 Size,
void * Allocref);
And the part I'm the least sure can be done in C# is the asynchronous event
mechanism. Here is one of the typefefs.
typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler)
(const MyAPI_UUID *UUID,
void* AppNotifyCallbackCtx,
MyAPI_ID ID,
uint32 Reserved,
MyAPI_Event EventType);
Can C# easily work with this API? (*)
Thanks!
-- Mark
(*) Several years ago I wrote some ugly VB6 code to deal with a DLL that had
VB-unfriendly pointers and unicode strings. Therefore I assume it is
"possible" to use this DLL from C#. I guess I'm asking whether or not it is
"easy" or "reasonable" to call the DLL from C#. 6 1639
Mark,
While you are using the stdcall convention for the functions, it's not
possible to tell whether or not you are exploring the functions correctly.
My guess is that yes, the functions are exported correctly, so you should
have no problem using this.
However, the only thing that is of concern is the memory management
routine. It looks like there is a routine for allocating memory, but I
can't see anything for deallocating memory. If you have that defined, then
you should be alright.
Other than that, there is no reason why you shouldn't be able to use
this from .NET.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I need to call a Win32 DLL. The API supports both Windows and Linux, but I'm only concerned with Windows. I'd like advice whether I can use C# or whether I'll have to dust off my old C++ books. I would prefer to learn C# rather than go back to C++.
The API starts with
#ifdef (WIN32) #define MyAPI __stdcall #else #define MyAPI #endif
There are bitmap mask #define statements.
All integer values are little-endian.
There are many "typedef" and "typedef struct" statements with char, const, void, sint8, uint8, uint16, uint32, and sint32 elements, arrays and pointers.
There are "typedef struct" statements with union elements.
To ease cross-platform use, the API defines its own memory management. This is one typedef:
typedef void * (MyAPI *MyAPI_REALLOC) (void * Memblock, uint32 Size, void * Allocref);
And the part I'm the least sure can be done in C# is the asynchronous event mechanism. Here is one of the typefefs.
typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler) (const MyAPI_UUID *UUID, void* AppNotifyCallbackCtx, MyAPI_ID ID, uint32 Reserved, MyAPI_Event EventType);
Can C# easily work with this API? (*)
Thanks!
-- Mark
(*) Several years ago I wrote some ugly VB6 code to deal with a DLL that had VB-unfriendly pointers and unicode strings. Therefore I assume it is "possible" to use this DLL from C#. I guess I'm asking whether or not it is "easy" or "reasonable" to call the DLL from C#.
Nicholas Paldino [.NET/C# MVP] wrote: Mark,
While you are using the stdcall convention for the functions, it's not possible to tell whether or not you are exploring the functions correctly. My guess is that yes, the functions are exported correctly, so you should have no problem using this.
However, the only thing that is of concern is the memory management routine. It looks like there is a routine for allocating memory, but I can't see anything for deallocating memory. If you have that defined, then you should be alright.
I just typed one of the five typedefs. There are the standard
*MyAPI_MALLOC, *MyAPI_FREE, *MyAPI_REALLOC and *MyAPI_CALLOC. There is also
a "wrapper" typedef:
typedef struct MyAPI_memory_functions {
MyAPI_MALLOC Malloc_func;
MyAPI_FREE Free_func;
MyAPI_REALLOC Realloc_func;
MyAPI_CALLOC Calloc_func;
void *AllocRef;
} MyAPI_MEMORY_FUNCS, *MyAPI_MEM_FUNCS_PTR;
Other than that, there is no reason why you shouldn't be able to use this from .NET.
Hope this helps.
It does indeed. I get to learn something new. Thanks.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... I need to call a Win32 DLL. The API supports both Windows and Linux, but I'm only concerned with Windows. I'd like advice whether I can use C# or whether I'll have to dust off my old C++ books. I would prefer to learn C# rather than go back to C++.
The API starts with
#ifdef (WIN32) #define MyAPI __stdcall #else #define MyAPI #endif
There are bitmap mask #define statements.
All integer values are little-endian.
There are many "typedef" and "typedef struct" statements with char, const, void, sint8, uint8, uint16, uint32, and sint32 elements, arrays and pointers.
There are "typedef struct" statements with union elements.
To ease cross-platform use, the API defines its own memory management. This is one typedef:
typedef void * (MyAPI *MyAPI_REALLOC) (void * Memblock, uint32 Size, void * Allocref);
And the part I'm the least sure can be done in C# is the asynchronous event mechanism. Here is one of the typefefs.
typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler) (const MyAPI_UUID *UUID, void* AppNotifyCallbackCtx, MyAPI_ID ID, uint32 Reserved, MyAPI_Event EventType);
Can C# easily work with this API? (*)
Thanks!
-- Mark
(*) Several years ago I wrote some ugly VB6 code to deal with a DLL that had VB-unfriendly pointers and unicode strings. Therefore I assume it is "possible" to use this DLL from C#. I guess I'm asking whether or not it is "easy" or "reasonable" to call the DLL from C#.
Mark,
You aren't going to be able to use function pointers in .NET 1.1 or
before. If that is how your API is defining the memory management
functions, then you will not be able to use it.
However, in .NET 2.0, you will be able to take a pointer in memory, and
assign it to a delegate, which you can then call from managed code. If you
can get this pointer from your API, then getting a callable delegate is
very, very simple.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Mark,
While you are using the stdcall convention for the functions, it's not possible to tell whether or not you are exploring the functions correctly. My guess is that yes, the functions are exported correctly, so you should have no problem using this.
However, the only thing that is of concern is the memory management routine. It looks like there is a routine for allocating memory, but I can't see anything for deallocating memory. If you have that defined, then you should be alright.
I just typed one of the five typedefs. There are the standard *MyAPI_MALLOC, *MyAPI_FREE, *MyAPI_REALLOC and *MyAPI_CALLOC. There is also a "wrapper" typedef:
typedef struct MyAPI_memory_functions { MyAPI_MALLOC Malloc_func; MyAPI_FREE Free_func; MyAPI_REALLOC Realloc_func; MyAPI_CALLOC Calloc_func; void *AllocRef; } MyAPI_MEMORY_FUNCS, *MyAPI_MEM_FUNCS_PTR;
Other than that, there is no reason why you shouldn't be able to use this from .NET.
Hope this helps.
It does indeed. I get to learn something new. Thanks.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... I need to call a Win32 DLL. The API supports both Windows and Linux, but I'm only concerned with Windows. I'd like advice whether I can use C# or whether I'll have to dust off my old C++ books. I would prefer to learn C# rather than go back to C++.
The API starts with
#ifdef (WIN32) #define MyAPI __stdcall #else #define MyAPI #endif
There are bitmap mask #define statements.
All integer values are little-endian.
There are many "typedef" and "typedef struct" statements with char, const, void, sint8, uint8, uint16, uint32, and sint32 elements, arrays and pointers.
There are "typedef struct" statements with union elements.
To ease cross-platform use, the API defines its own memory management. This is one typedef:
typedef void * (MyAPI *MyAPI_REALLOC) (void * Memblock, uint32 Size, void * Allocref);
And the part I'm the least sure can be done in C# is the asynchronous event mechanism. Here is one of the typefefs.
typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler) (const MyAPI_UUID *UUID, void* AppNotifyCallbackCtx, MyAPI_ID ID, uint32 Reserved, MyAPI_Event EventType);
Can C# easily work with this API? (*)
Thanks!
-- Mark
(*) Several years ago I wrote some ugly VB6 code to deal with a DLL that had VB-unfriendly pointers and unicode strings. Therefore I assume it is "possible" to use this DLL from C#. I guess I'm asking whether or not it is "easy" or "reasonable" to call the DLL from C#.
Nicholas Paldino [.NET/C# MVP] wrote: Mark,
You aren't going to be able to use function pointers in .NET 1.1 or before. If that is how your API is defining the memory management functions, then you will not be able to use it.
Bummer. They can't be called from C# unmanaged code either?
However, in .NET 2.0, you will be able to take a pointer in memory, and assign it to a delegate, which you can then call from managed code. If you can get this pointer from your API, then getting a callable delegate is very, very simple.
My MSDN subscription has lapsed so this doesn't appear to be an option.
Plus they are betas and I need to distribute the app to users.
-- Mark "Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:OH*************@TK2MSFTNGP15.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Mark,
While you are using the stdcall convention for the functions, it's not possible to tell whether or not you are exploring the functions correctly. My guess is that yes, the functions are exported correctly, so you should have no problem using this.
However, the only thing that is of concern is the memory management routine. It looks like there is a routine for allocating memory, but I can't see anything for deallocating memory. If you have that defined, then you should be alright.
I just typed one of the five typedefs. There are the standard *MyAPI_MALLOC, *MyAPI_FREE, *MyAPI_REALLOC and *MyAPI_CALLOC. There is also a "wrapper" typedef:
typedef struct MyAPI_memory_functions { MyAPI_MALLOC Malloc_func; MyAPI_FREE Free_func; MyAPI_REALLOC Realloc_func; MyAPI_CALLOC Calloc_func; void *AllocRef; } MyAPI_MEMORY_FUNCS, *MyAPI_MEM_FUNCS_PTR;
Other than that, there is no reason why you shouldn't be able to use this from .NET.
Hope this helps.
It does indeed. I get to learn something new. Thanks.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... I need to call a Win32 DLL. The API supports both Windows and Linux, but I'm only concerned with Windows. I'd like advice whether I can use C# or whether I'll have to dust off my old C++ books. I would prefer to learn C# rather than go back to C++.
The API starts with
#ifdef (WIN32) #define MyAPI __stdcall #else #define MyAPI #endif
There are bitmap mask #define statements.
All integer values are little-endian.
There are many "typedef" and "typedef struct" statements with char, const, void, sint8, uint8, uint16, uint32, and sint32 elements, arrays and pointers.
There are "typedef struct" statements with union elements.
To ease cross-platform use, the API defines its own memory management. This is one typedef:
typedef void * (MyAPI *MyAPI_REALLOC) (void * Memblock, uint32 Size, void * Allocref);
And the part I'm the least sure can be done in C# is the asynchronous event mechanism. Here is one of the typefefs.
typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler) (const MyAPI_UUID *UUID, void* AppNotifyCallbackCtx, MyAPI_ID ID, uint32 Reserved, MyAPI_Event EventType);
Can C# easily work with this API? (*)
Thanks!
-- Mark
(*) Several years ago I wrote some ugly VB6 code to deal with a DLL that had VB-unfriendly pointers and unicode strings. Therefore I assume it is "possible" to use this DLL from C#. I guess I'm asking whether or not it is "easy" or "reasonable" to call the DLL from C#.
Mark,
If you do not have function definitions that are not exported, then in
..NET 1.1, you won't be able to make a call.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message
news:uU*************@TK2MSFTNGP09.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Mark,
You aren't going to be able to use function pointers in .NET 1.1 or before. If that is how your API is defining the memory management functions, then you will not be able to use it.
Bummer. They can't be called from C# unmanaged code either?
However, in .NET 2.0, you will be able to take a pointer in memory, and assign it to a delegate, which you can then call from managed code. If you can get this pointer from your API, then getting a callable delegate is very, very simple.
My MSDN subscription has lapsed so this doesn't appear to be an option. Plus they are betas and I need to distribute the app to users.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:OH*************@TK2MSFTNGP15.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Mark,
While you are using the stdcall convention for the functions, it's not possible to tell whether or not you are exploring the functions correctly. My guess is that yes, the functions are exported correctly, so you should have no problem using this.
However, the only thing that is of concern is the memory management routine. It looks like there is a routine for allocating memory, but I can't see anything for deallocating memory. If you have that defined, then you should be alright.
I just typed one of the five typedefs. There are the standard *MyAPI_MALLOC, *MyAPI_FREE, *MyAPI_REALLOC and *MyAPI_CALLOC. There is also a "wrapper" typedef:
typedef struct MyAPI_memory_functions { MyAPI_MALLOC Malloc_func; MyAPI_FREE Free_func; MyAPI_REALLOC Realloc_func; MyAPI_CALLOC Calloc_func; void *AllocRef; } MyAPI_MEMORY_FUNCS, *MyAPI_MEM_FUNCS_PTR;
Other than that, there is no reason why you shouldn't be able to use this from .NET.
Hope this helps.
It does indeed. I get to learn something new. Thanks.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... > I need to call a Win32 DLL. The API supports both Windows and > Linux, but I'm only concerned with Windows. I'd like advice > whether I can use C# or whether I'll have to dust off my old C++ > books. I would prefer to learn C# > rather than go back to C++. > > The API starts with > > #ifdef (WIN32) > #define MyAPI __stdcall > #else > #define MyAPI > #endif > > There are bitmap mask #define statements. > > All integer values are little-endian. > > There are many "typedef" and "typedef struct" statements with char, > const, void, sint8, uint8, uint16, uint32, and sint32 elements, > arrays and pointers. > > There are "typedef struct" statements with union elements. > > To ease cross-platform use, the API defines its own memory > management. This > is one typedef: > > typedef void * (MyAPI *MyAPI_REALLOC) > (void * Memblock, > uint32 Size, > void * Allocref); > > And the part I'm the least sure can be done in C# is the > asynchronous event > mechanism. Here is one of the typefefs. > > typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler) > (const MyAPI_UUID *UUID, > void* AppNotifyCallbackCtx, > MyAPI_ID ID, > uint32 Reserved, > MyAPI_Event EventType); > > Can C# easily work with this API? (*) > > Thanks! > > -- Mark > > (*) Several years ago I wrote some ugly VB6 code to deal with a DLL > that had > VB-unfriendly pointers and unicode strings. Therefore I assume it > is "possible" to use this DLL from C#. I guess I'm asking whether > or not it is > "easy" or "reasonable" to call the DLL from C#.
Maybe I'm mising something, but I don't think you need to pass function
pointers to C++, the memory management functions are implemented in native
C++ code and called from C++ don't they?
Willy.
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message
news:uU*************@TK2MSFTNGP09.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Mark,
You aren't going to be able to use function pointers in .NET 1.1 or before. If that is how your API is defining the memory management functions, then you will not be able to use it.
Bummer. They can't be called from C# unmanaged code either?
However, in .NET 2.0, you will be able to take a pointer in memory, and assign it to a delegate, which you can then call from managed code. If you can get this pointer from your API, then getting a callable delegate is very, very simple.
My MSDN subscription has lapsed so this doesn't appear to be an option. Plus they are betas and I need to distribute the app to users.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:OH*************@TK2MSFTNGP15.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Mark,
While you are using the stdcall convention for the functions, it's not possible to tell whether or not you are exploring the functions correctly. My guess is that yes, the functions are exported correctly, so you should have no problem using this.
However, the only thing that is of concern is the memory management routine. It looks like there is a routine for allocating memory, but I can't see anything for deallocating memory. If you have that defined, then you should be alright.
I just typed one of the five typedefs. There are the standard *MyAPI_MALLOC, *MyAPI_FREE, *MyAPI_REALLOC and *MyAPI_CALLOC. There is also a "wrapper" typedef:
typedef struct MyAPI_memory_functions { MyAPI_MALLOC Malloc_func; MyAPI_FREE Free_func; MyAPI_REALLOC Realloc_func; MyAPI_CALLOC Calloc_func; void *AllocRef; } MyAPI_MEMORY_FUNCS, *MyAPI_MEM_FUNCS_PTR;
Other than that, there is no reason why you shouldn't be able to use this from .NET.
Hope this helps.
It does indeed. I get to learn something new. Thanks.
-- Mark
"Mark Jerde" <ma********@verizon.no.spam.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... > I need to call a Win32 DLL. The API supports both Windows and > Linux, but I'm only concerned with Windows. I'd like advice > whether I can use C# or whether I'll have to dust off my old C++ > books. I would prefer to learn C# > rather than go back to C++. > > The API starts with > > #ifdef (WIN32) > #define MyAPI __stdcall > #else > #define MyAPI > #endif > > There are bitmap mask #define statements. > > All integer values are little-endian. > > There are many "typedef" and "typedef struct" statements with char, > const, void, sint8, uint8, uint16, uint32, and sint32 elements, > arrays and pointers. > > There are "typedef struct" statements with union elements. > > To ease cross-platform use, the API defines its own memory > management. This > is one typedef: > > typedef void * (MyAPI *MyAPI_REALLOC) > (void * Memblock, > uint32 Size, > void * Allocref); > > And the part I'm the least sure can be done in C# is the > asynchronous event > mechanism. Here is one of the typefefs. > > typedef MyAPI_RETURN (MyAPI *MyAPI_ModuleEventHandler) > (const MyAPI_UUID *UUID, > void* AppNotifyCallbackCtx, > MyAPI_ID ID, > uint32 Reserved, > MyAPI_Event EventType); > > Can C# easily work with this API? (*) > > Thanks! > > -- Mark > > (*) Several years ago I wrote some ugly VB6 code to deal with a DLL > that had > VB-unfriendly pointers and unicode strings. Therefore I assume it > is "possible" to use this DLL from C#. I guess I'm asking whether > or not it is > "easy" or "reasonable" to call the DLL from C#.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fabian Müller |
last post by:
Hi all,
my question is as follows:
If have a class X and a class Y derived from X.
Constructor of X is X(param1, param2) .
Constructor of Y is Y(param1, ..., param4) .
|
by: hasho |
last post by:
Why is "call by address" faster than "call by value"?
|
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage...
|
by: Amaryllis |
last post by:
I'm trying to call a CL which is located on our AS400 from a Windows
application. I've tried to code it in different ways, but I seem to
get the same error every time. Does anyone have any clue...
|
by: mitchellpal |
last post by:
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?
|
by: shsingh |
last post by:
I have a class A containing some map as data variables. I creat an
object of class A on heap by allocatiing memory by using "malloc". This
will return me the required memory but the object is not...
|
by: cberthu |
last post by:
Hi all,
Is it possible to have two connects in the same rexx script to
different DB's?
I have to get data form on DB (with specifics selects and filter out
some values with RExx) and save the...
|
by: CryptiqueGuy |
last post by:
Consider the variadic function with the following prototype:
int foo(int num,...);
Here 'num' specifies the number of arguments, and assume that all the
arguments that should be passed to this...
|
by: Rahul |
last post by:
Hi Everyone,
I have the following code and i'm able to invoke the destructor
explicitly but not the constructor. and i get a compile time error
when i invoke the constructor, why is this so?
...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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: 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?
| |