Re: PInvoke an old DLL file
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 17 May 2007 14:53:31 -0400
You would need to post the typedefs or structure definitions for the
members in the structure which are not standard types (what is Rescode_t for
example).
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"gregarican" <greg.kujawa@xxxxxxxxx> wrote in message
news:1179427137.953943.312620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 17, 2:10 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
You are going to have to create a structure which has IntPtr members
which act as the pointers.
Once you do that, you will also have to define the structures/types
that
the pointers point to.
If you have to allocate the memory for these structures before you
pass
the structure to the function through P/Invoke, you will have to use one
of
the static Alloc* methods on the Marshal class in order to allocate
memory
(or use unsafe code, which would make it a lot easier) and then set the
values of those fields to the blocks of memory that you allocated.
On return, you have to pass those pointers to the PtrToStructure
method
to read the unmanaged memory and return a managed representation to you.
Again, unsafe code would probably be very helpful here, as you could just
access the pointers in memory directly.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"gregarican" <greg.kuj...@xxxxxxxxx> wrote in message
news:1179424736.339698.253590@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am trying to port a legacy CTI application written in another
programming language to C# 2005. From my initial research into it I
see I can utilize the DllImport method to tap into the DLL file (which
is CTSA32.DLL). From there I have documented API for the various C
methods that are invoked, most all of which have an in and an out. You
pass in a data structure and get a data structure returned back.
What's the most straightforward way of mimicing the packed pointers
that are in these C data structures? The other data types I think I
have a handle on. Most of them are unsigned short or else enums. But
the packed pointers seems to be another matter? Here's a sample data
structure that opens the initial CTI session stream:
#include <acs.h>
#include <csta.h>
RetCode_t acsOpenStream(
ACSHandle_t *acsHandle, /* RETURN */
InvokeIDType_t invokeIDType, /* INPUT */
InvokeID_t invokeID, /* INPUT */
StreamType_t streamType, /* INPUT */
ServerID_t *serverID, /* INPUT */
LoginID_t *loginID, /* INPUT */
Passwd_t *passwd, /* INPUT */
AppName_t *applicationName, /* INPUT */
Level_t acsLevelReq /* INPUT */
Version_t *apiVer, /* INPUT */
unsigned short sendQSize, /* INPUT */
unsigned short sendExtraBufs, /* INPUT */
unsigned short recvQSize, /* INPUT */
unsigned short recvExtraBufs /* INPUT */
PrivateData_t *privateData); /* INPUT */
How do I create a C# struct that contains members that are packed
pointers?- Hide quoted text -
- Show quoted text -
Ouch. Sounds like some serious groundwork to get things started. But I
have to do it in any event. Could you please post a brief sample of
unsafe code that could achieve what I'm looking to do with this basic
structure that I listed? That should be enough to get my head around
this and get started. I'd really appreciate it :-)
.
- Follow-Ups:
- Re: PInvoke an old DLL file
- From: gregarican
- Re: PInvoke an old DLL file
- References:
- PInvoke an old DLL file
- From: gregarican
- Re: PInvoke an old DLL file
- From: Nicholas Paldino [.NET/C# MVP]
- Re: PInvoke an old DLL file
- From: gregarican
- PInvoke an old DLL file
- Prev by Date: Re: PInvoke an old DLL file
- Next by Date: Re: PInvoke an old DLL file
- Previous by thread: Re: PInvoke an old DLL file
- Next by thread: Re: PInvoke an old DLL file
- Index(es):
Relevant Pages
|