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