From: jmp on
Hello,

I am facing the same problem to you few years later ....
I would like to know if you have found an issue to call csta32 function from you c# code ?

I hope you will see my post ...

Thanks,
Regards.



gregarican wrote:

Re: More PInvoke Shenanigans
20-May-07

Just after posting this I saw that I needed to change the C# ulong to
System.UInt32. Now I get past that error and can at least get a result
code back from the csta32.dll. So I am on my way!!!

Previous Posts In This Thread:

On Sunday, May 20, 2007 2:41 PM
gregarican wrote:

More PInvoke Shenanigans
A couple of days ago I was debating about whether to use C++/CLI or C#
2005's PInvoke in order to tie in my VS 2005 app with a legacy
csta32.dll file. So far I have tried to call one method out of the
csta32.dll and wind up with the PInvoke stack imbalance error. Here
are the data types my C# mappings are based on:

typedef unsigned long ACSHandle_t;

typedef enum {
APP_GEN_ID, /* application will provide invokeIDs; any 4-byte value
is legal */
LIB_GEN_ID /* library will generate invokeIDs in the range 1-32767
*/
} InvokeIDType_t;

typedef unsigned long InvokeID_t;

typedef enum StreamType_t {
ST_CSTA = 1,
ST_OAM = 2,
ST_DIRECTORY = 3,
ST_NMSRV = 4
} StreamType_t;

typedef char ServerID_t[49];
typedef char LoginID_t[49];
typedef char Passwd_t[49];
typedef char AppName_t[21];

typedef enum Level_t {
ACS_LEVEL1 = 1,
ACS_LEVEL2 = 2,
ACS_LEVEL3 = 3,
ACS_LEVEL4 = 5
} Level_t;

typedef char Version_t[21];

typedef unsigned short SendQSize_t;
typedef unsigned short SendExtraBufs_t;
typedef unsigned short RecvQSize_t;
typedef unsigned short RecvExtraBufs_t;

typedef struct PrivateData_t {
char vendor[32];
unsigned short length;
char data[1]; /* actual length determined by application */
} PrivateData_t;

And here is what I have so far in C# to translate between the managed
and unmanaged elements:

[DllImport("csta32.dll")]
public static extern int acsOpenStream(ref IntPtr acsHandle, int
invokeIDType, ulong invokeID, int streamType,
ref string serverID, ref string loginID, ref string passwd, ref
string applicationName, int acsLevelReq,
ref string apiVer, ushort sendQSize, ushort sendExtraBufs, ushort
recvQSize, ushort recvExtraBufs,
ref PrivateData_t priv);

public struct PrivateData_t
{
[ MarshalAs( UnmanagedType.ByValArray, SizeConst=32)]
public char [] vendor;
public ushort length;
[ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
public char [] data;
};

The acsHandle is derived by the following client routine when I invoke
the acsOpenStream() method in C#:

ulong acsHandle = 0;
IntPtr ptrAcsHandle = (IntPtr)acsHandle;

Am I missing something obvious here? This all seems relatively complex
to me and I'm struggling with getting this first method knocked out. I
read that in C++ the long data type is 4 bytes, while in C# it's 8
bytes. Is this causing the hangup?

On Sunday, May 20, 2007 2:51 PM
gregarican wrote:

Re: More PInvoke Shenanigans
Just after posting this I saw that I needed to change the C# ulong to
System.UInt32. Now I get past that error and can at least get a result
code back from the csta32.dll. So I am on my way!!!


Submitted via EggHeadCafe - Software Developer Portal of Choice
XAML Organizer
http://www.eggheadcafe.com/tutorials/aspnet/ac373a5d-e497-4e07-9186-12166e83a024/xaml-organizer.aspx