problem w/ returning char * from an unmanaged dll

B

bgibbons

Hello,
in my asp.net app I have declared the following

[DllImport("UADLL.dll",EntryPoint="GetTMDataRepositoryUsage",CharSet=CharSet
..Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int
GetTMDataRepositoryUsage([Out][MarshalAs(UnmanagedType.LPStr)] ref string
szComputerName)/


while in my unmanaged dll I have
extern "C" __declspec(dllexport) int GetTMConfigRepositoryUsage ( char*
szComputerName )

I call the function in asp.net this way
string szComputerName = "test";

GetTMDataRepositoryUsage ( szComputerName ) ;

When i debug the code "test" is passed in correctly to
GetTMDataRepositoryUsage function but when it returns it's always NULL.

Any assistance is greatly appreciated.

Bill
 
M

Mattias Sjögren

[DllImport("UADLL.dll",EntryPoint="GetTMDataRepositoryUsage",CharSet=CharSet
.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int
GetTMDataRepositoryUsage([Out][MarshalAs(UnmanagedType.LPStr)] ref string
szComputerName)/


Try it like this

public static extern int
GetTMDataRepositoryUsage(StringBuilder szComputerName);



Mattias
 
J

Jeffrey Tan[MSFT]

Hi Bill,

Have you tried Mattias's suggestion? Does it work for you?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hello Jeffrey

Good news

Mattias's idea worked.

StringBuilder szComputerName = new StringBuilder("")
GetTMDataRepositoryUsage( szComputerName )

Thank you
Bill
 
J

Jeffrey Tan[MSFT]

Hi Bill,

Oh, I am glad to hear that :)

Actually, I have tested his solution for you, it should work. If you need
further help, please feel free to post.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top