|
|
|
start date: Fri, 29 Jun 2007 17:02:09 +0530,
posted on: microsoft.public.dotnet.framework.interop
back
| Thread Index |
|
1
kris
|
|
2
Mattias Sjgren
|
|
3
kris
|
|
4
Christian Fröschlin
|
|
5
kris
|
Enum
Hi ,
I have a problem passing enum as a parameter in my C# code.
I tried declaring the parameter as int as well as long . I even tried using
MarshalAs attribute.
I am getting exception saying parameters are not matching.
This code is talking to a C++ DLL that takes enum as one of the parameters.
Regards
Kris
Date:Fri, 29 Jun 2007 17:02:09 +0530
Author:
|
Re: Enum
>I tried declaring the parameter as int as well as long .
Why not the actual enum type?
>I am getting exception saying parameters are not matching.
Can you please post the exact exception type and error message, as
well as the signatures (both in C++ and C#) of the function you're
caling.
Mattias
--
Mattias Sjgren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Date:Sat, 30 Jun 2007 22:44:28 +0200
Author:
|
Re: Enum
Hi mattias,
I have mapped it to enum , but still it does not work.
Can you please help me.
Please check below the exact signatures for the functions.
Also please check the structures declarations in both C# and c++.
/////////////////////////////////////////////////////////////////////////////////////
//this is in C++
DLL_EXPORT long __stdcall Connect(char *pServer, long port, XS_Mode mode);
/////////////////////////////////////////////////////////////////////////////////////
//this is in C#
[DllImport("compt.dll", CharSet = CharSet.Ansi,CallingConvention =
CallingConvention.StdCall)]
public static extern long Connect(string pServer, long port, XMode mode);
/////////////////////////////////////////////////////////////////////////////////////
//this is in C++
typedef enum _X_Mode {
NONE = 1,
SERVER = 2,
LOCAL = 3
} XSMode;
/////////////////////////////////////////////////////////////////////////////////////
//this is in C#
public enum XMode
{
NONE = 1,
SERVER = 2,
LOCAL = 3
};
/////////////////////////////////////////////////////////////////////////////////////
"Mattias Sjgren" wrote in message
news:e6LnNe1uHHA.5036@TK2MSFTNGP03.phx.gbl...
>
>>I tried declaring the parameter as int as well as long .
>
> Why not the actual enum type?
>
>
>>I am getting exception saying parameters are not matching.
>
> Can you please post the exact exception type and error message, as
> well as the signatures (both in C++ and C#) of the function you're
> caling.
>
>
> Mattias
>
> --
> Mattias Sjgren [C# MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
Date:Mon, 2 Jul 2007 16:07:13 +0530
Author:
|
Re: Enum
kris wrote:
> public static extern long Connect(string pServer, long port, XMode mode);
C# "long" ist 64-bit, so you should use int for port and return value.
Date:Mon, 02 Jul 2007 15:17:48 +0200
Author:
|
Re: Enum
Hi Chris,
Thanks a lot, it works.
Regards
Kris
"Christian Frschlin" wrote in message
news:f6attu$n0s$1@svr7.m-online.net...
> kris wrote:
>
>> public static extern long Connect(string pServer, long port, XMode mode);
>
> C# "long" ist 64-bit, so you should use int for port and return value.
Date:Wed, 4 Jul 2007 09:45:12 +0530
Author:
|
|
|