473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem w/ returning char * from an unmanaged dll

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

[DllImport("UADLL.dll",EntryPoint="GetTMDataReposit oryUsage",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

Nov 16 '05 #1
4 1171
[DllImport("UADLL.dll",EntryPoint="GetTMDataReposit oryUsage",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

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

Nov 16 '05 #3
Hello Jeffrey

Good news

Mattias's idea worked.

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

Thank you
Bill
Nov 16 '05 #4
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.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jon Skeet | last post by:
I've just noticed something rather odd and disturbing. The following code displays "True": using System; class Test { public static void Main(string args) { string x = new string...
7
by: sienaman | last post by:
I have a C# dll with a COM interface that is successfully call by a C++ client. One of the parameters is a string, the method looks like void Goofy(string strUserInput, out string strOutput); ...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
5
by: Mark Ingram | last post by:
Hi, how can i return an array of strings from an unmanaged c++ dll into a c# application? cheers Mark
7
by: Kristof Thys via .NET 247 | last post by:
Post a new message to microsoft.public.dotnet.languages.vc http://www.dotnet247.com/247reference/default.aspx Hello, I've been struggling for weeks with this problem, I hope I find some...
3
by: Steve | last post by:
I'm trying to call some unmanaged methods from a DLL. I did this awhile ago, a couple years ago... I'm a little rusty. I will show you what I'm dealing with: <unmanaged function signature>...
7
by: ConfNoob | last post by:
part 1: there is a NON - COM unmanaged dll in VC++ 6.0 BOOL function(char * name, int nOption) part 2: there is a C# web service that has to consume the above DLL used DLLImport to call the...
0
by: rkpatil | last post by:
have an unmanaged C++ DLL with following method: the DLL interface for unmanaged C++ is: SendCommand(void *h, char *c, char *d, char *b); the declaration in C# is: unsafe public static...
3
by: =?Utf-8?B?QzBkM3I=?= | last post by:
have an unmanaged C++ DLL with following method: the DLL interface for unmanaged C++ is: SendCommand(void *h, char *c, char *d, char *b); the declaration in C# is: unsafe public static...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.