Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2006

Tip: Looking for answers? Try searching our database.

P/Invoke on C DLL which takes char * parameter ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FX - 12 Jul 2006 19:14 GMT
Hi all,
I'm programming a C# application which invokes a DLL (written in standard
C).
I have tried many things but any success since the beginning of the weeks.

Here is the C prototype:

unsigned short GetField ( unsigned short fieldId, char* fieldValue, size_t*
FieldSize);

This method should return a value in fieldValue.

Here is my DLLImport:
[DllImport("reader20.dll", CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
private static extern ushort GetField (
       ushort fieldId,
       StringBuilder fieldValue,
       out int TailleMax
   );

Here is my call:
int s;
StringBuilder value = new StringBuilder();
SGD_LireChamp(123, value, out s);

I don't understand why "value" still remain to empty string.

Is there something wrong in my code? Do you have any alternative?

Hope someone can help me.
Thanks

Franck

NB:
This DLL can not be modified because it is shipped by a provider.
Mattias Sjögren - 12 Jul 2006 22:59 GMT
>I don't understand why "value" still remain to empty string.
>
>Is there something wrong in my code? Do you have any alternative?

Does the function return text or binary data? Do you have any
existing, working code calling the function you can post that we can
compare with?

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Fx - 26 Jul 2006 13:42 GMT
Hi,
I've found !
Just replace "private" attribute by "public" and parameters are correctly
handled by P/Invoke.

> Hi all,
> I'm programming a C# application which invokes a DLL (written in standard
[quoted text clipped - 33 lines]
> NB:
> This DLL can not be modified because it is shipped by a provider.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.