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 / September 2005

Tip: Looking for answers? Try searching our database.

Passing Parameter from C# to C++ dll

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anitha R - 09 Sep 2005 09:15 GMT
Hello,
I am a newbie to C#.I have been working in VC++ 6.0 .The dll worked fine in
VC++
C#  application uses a unmanaged C++ dll compiled in VS.NET.
The C# passes a char[ ] or byte[ ] to WriteCard(int Sector,unsigned char *
WriteBuff).
The writebuff is becoming NULL.I tried by displaying Messagebox in my dll for
step by step debugging.
The writebuff is nulling.Nothing is getting stored even though i initialize
it in C#.
Please help me i am unable to know what is the problem.
In C# the [DllImport("Mifare.dll" , CharSet =CharSet.Ansi )]
            public static extern  long WriteCard(long Sector, char[] WriteBuff );
string temp = "hello";
WriteBuff = temp.toCharArray();
Plz Help.
Thanks in advance,
Anitha
Egbert Nierop (MVP for IIS) - 09 Sep 2005 11:17 GMT
> Hello,
> I am a newbie to C#.I have been working in VC++ 6.0 .The dll worked fine
[quoted text clipped - 3 lines]
> The C# passes a char[ ] or byte[ ] to WriteCard(int Sector,unsigned char *
> WriteBuff).

IN C++ an unsigned char is, in fact a BYTE while a char in .NET is a wchar_t
a long in C++ (win32) is an int in .NET.

> The writebuff is becoming NULL.I tried by displaying Messagebox in my dll
> for
[quoted text clipped - 5 lines]
> In C# the [DllImport("Mifare.dll" , CharSet =CharSet.Ansi )]
> public static extern  long WriteCard(long Sector, char[] WriteBuff );

[DllImport("Mifare.dll" , CharSet =CharSet.Ansi )]
[MarshalAs(UnmanagedType.LPStr)]
public static extern  long WriteCard(int Sector, string WriteBuff );

Success!

> string temp = "hello";
> WriteBuff = temp.toCharArray();
> Plz Help.
> Thanks in advance,
> Anitha
Anitha R - 09 Sep 2005 11:57 GMT
Hello Egbert,
Thanks for the reply.
I am passing a string but when the string is being  passed to the dll it is
displaying null.
I tried the code which you suggested still the same.
other functions in that dll are executed properly.But only for this
particular function.
Is it the dll problem or the function.

Regards,
Anitha
Anitha R - 09 Sep 2005 12:04 GMT
Hi Egbert,
Thanks a lot its working fine after using that code .
I need one more help can you tell me which book  should i but for .NET
framework along with C#.
I want to continue my profession in this technology.
Thanks,
Anitha
>> Hello,
>> I am a newbie to C#.I have been working in VC++ 6.0 .The dll worked fine
[quoted text clipped - 22 lines]
>> Thanks in advance,
>> Anitha
Egbert Nierop (MVP for IIS) - 09 Sep 2005 16:11 GMT
> Hi Egbert,
> Thanks a lot its working fine after using that code .
[quoted text clipped - 4 lines]
> Anitha
>>> Hello,

The one that I like much, is written by a MS C# team member, who's name I
forgot, I just lent the book to someone.
Egbert Nierop (MVP for IIS) - 09 Sep 2005 16:12 GMT
> Hi Egbert,
> Thanks a lot its working fine after using that code .
> I need one more help can you tell me which book  should i but for .NET
> framework along with C#.
> I want to continue my profession in this technology.
> Thanks,

I remember him,
He's Eric Gunnerson.

Cheers.
Anitha R - 12 Sep 2005 05:28 GMT
Hi, Egbert,
Thanks a lot .
>> Hi Egbert,
>> Thanks a lot its working fine after using that code .
[quoted text clipped - 7 lines]
>
>Cheers.
Egbert Nierop (MVP for IIS) - 09 Sep 2005 11:56 GMT
> Hello,
> I am a newbie to C#.I have been working in VC++ 6.0 .The dll worked fine
[quoted text clipped - 3 lines]
> The C# passes a char[ ] or byte[ ] to WriteCard(int Sector,unsigned char *
> WriteBuff).

IN C++ an unsigned char is, in fact a BYTE while a char in .NET is a wchar_t
a long in C++ (win32) is an int in .NET.

> The writebuff is becoming NULL.I tried by displaying Messagebox in my dll
> for
[quoted text clipped - 5 lines]
> In C# the [DllImport("Mifare.dll" , CharSet =CharSet.Ansi )]
> public static extern  long WriteCard(long Sector, char[] WriteBuff );

[DllImport("Mifare.dll" , CharSet =CharSet.Ansi )]

public static extern  long WriteCard(int Sector,
[MarshalAs(UnmanagedType.LPStr)]
string WriteBuff );

Success!

> string temp = "hello";
> WriteBuff = temp.toCharArray();
> Plz Help.
> Thanks in advance,
> Anitha

Rate this thread:







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.