HighTechTalks DotNet Forums  

Enum

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Enum in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
kris
 
Posts: n/a

Default Enum - 06-29-2007 , 07:32 AM






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





Reply With Quote
  #2  
Old   
kris
 
Posts: n/a

Default Re: Enum - 07-02-2007 , 06:37 AM






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 Sjögren" <mattias.dont.want.spam (AT) mvps (DOT) org> wrote

Quote:
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 Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



Reply With Quote
  #3  
Old   
kris
 
Posts: n/a

Default Re: Enum - 07-04-2007 , 12:15 AM



Hi Chris,

Thanks a lot, it works.

Regards
Kris


"Christian Fröschlin" <froeschlin (AT) mvtec (DOT) com> wrote

Quote:
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.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.