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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a native dll from my managed dll

Status
Not open for further replies.

d00ape

Programmer
Apr 2, 2003
171
0
0
SE
I’m about to call a function in a native windows dll from my managed C# dll project. I want the function to return some kind of string (char*) so I get it as a System.String in my mandaged dll.

How can I do that? I’ve tried to add CLR support on my native dll but for different reasons it can’t compile with that option.
 
d00ape,

If I'm not mistaken (though I could be), you cannot have any kind of pointer reference in managed code...maybe you should have just an unmanaged method in your code that references it and converts it to a char[] or a string. Make the method private, and have a managed public method that handles the call into the unmanaged method. I could be way off, but I would think you can do it this way.

Good luck!
-Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
To what I understand, you're posting is related to, not how to import the native function, but the function signature in the native DLL itself.
I’ve tried to add CLR support on my native dll but for different reasons it can’t compile with that option.

Try posting this on the C/C++ forum.

[wink]

PS. IMHO, It's best to return pointers via parameters (like a ref/out on .NET) due to variable scope issues on C/C++. If you take a look on other Win32 APIs like GetTempPath, they return strings via a parameter pointing to a buffer that will contain the string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top