Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dll problems

Status
Not open for further replies.

ern297

Programmer
Nov 28, 2002
13
ES
I am trying to reuse in C# one function written in Visual C++ 6.0 that is in a DLL. Function has the following head:

type_enum name_function(
unsigned long *var1,
unsigned long var2,
wchar_t *var3);

I am trying to use the following thing, but it does not work.

[DllImport("library.dll", EntryPoint="name_function")]
static extern type_enum name_function(
ref ulong var1,
ulong var2,
ref char var3);

Could somebody help me?
 
I have read in MSDN that for passing structures as attributes to an unmanaged function you need to use a special mechanism, by using the StructLayout attribute. I am only guessing now, but isn't it necessary to use this also when the function returns a structure? Have you tried to do a platform invoke with a function that returns a simple type (e.g. int)?
If that's not it, could you specify the error message(s) you receive when you run your program?
 
I've rewrite my DLL to:

[DllImport("myDll.dll", EntryPoint="theFunction")]
public static extern type_enum myFunction(
[MarshalAs(UnmanagedType.U8)]ref ulong var1,
[MarshalAs(UnmanagedType.U8)]ulong var2,
[MarshalAs(UnmanagedType.LPWStr)]ref char var3);

I don't pass any structure (I think. It's only an enum type), but I have the next error:

No se pueden calcular referencias de parameter #3: combinación de tipos administrado y no administrado no válida (los caracteres deben estar emparejados con U1 o U2).


I traduce it as:

References of parameter # 3 cannot be calculated: combination of types administered and not administered is not worth (the characters must be matched with U1 or U2).


I don't understand where I must use the StructLayout that you say. Could you help me?
 
Thanks for everything, but finally I have obtained it!
This is the 'winner code':

[DllImport("myLib.dll", EntryPoint="theFunction")]
public static extern TYPE_ENUM myFunction(
[MarshalAs(UnmanagedType.U4)]ref uint var1,
[MarshalAs(UnmanagedType.U4)]uint var2,
[MarshalAs(UnmanagedType.U2)]ref char var3);

 
Yes, after seeing the error message it gets clear...
I'm glad that you did it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top