473,388 Members | 1,417 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,388 software developers and data experts.

Data Errors When Calling Unmanaged VC6 DLL

Hi All, I Have A Few Problems with a unmanged DLL (VC6) sending back data to
a C# application. The DLL is passed 10 "strings" (char* in the dll), which
should then be updated - in other words i want to pass some strings to the
dll by reference - it is called like this

s1 = enc.GetBytes(lat);
s2 = enc.GetBytes(lon);
s3 = enc.GetBytes(Sats);
s4 = enc.GetBytes(height);
s5 = enc.GetBytes(pDop);
s6 = enc.GetBytes(fp6);
s7 = enc.GetBytes(fp7);
s8 = enc.GetBytes(fp8);
s9 = enc.GetBytes(fp9);
s10 = enc.GetBytes(fp10);

MMGPS.PNT1_TO_AV(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);

lat = enc.GetString(s1);
lon = enc.GetString(s2);
Sats = enc.GetString(s5);
height = enc.GetString(s3);
pDop= enc.GetString(s4);
fp6 = enc.GetString(s6);
fp7 = enc.GetString(s7);
fp8 = enc.GetString(s8);
fp9 = enc.GetString(s9);
fp10 = enc.GetString(s10);

The Dll Code get the striings okay, proceeds with the processing and updats
them in the dll with the returned version. But when the data gets brought
back to the calling program, it appears that the C# code is only picked up
the first char of the string: so instead of getting 190311.11, it gets 1, and
instead of 44.898 it will get 4, does anybody have any suggestions about what
is cxausing this?

Andrew.

PS here are the C++ and C# function declatations.

int _stdcall PNT1_TO_AV(char* fp1, char* fp2, char* fp3, char* fp4, char*
fp5, char* fp6,
char* fp7, char* fp8, char* fp9, char* fp10)
{

}

[DllImport("MMGPS", EntryPoint = "PNT1_TO_AV", ExactSpelling = true, CharSet
= CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void PNT1_TO_AV(
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp1,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp2,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp3,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp4,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp5,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp6,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp7,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp8,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp9,
[MarshalAs(UnmanagedType.LPArray)]
byte[] fp10);
Nov 17 '05 #1
2 1445
The Dll Code get the striings okay, proceeds with the processing and updats
them in the dll with the returned version. But when the data gets brought
back to the calling program, it appears that the C# code is only picked up
the first char of the string: so instead of getting 190311.11, it gets 1, and
instead of 44.898 it will get 4, does anybody have any suggestions about what
is cxausing this?
What kind of encoding is the enc variable representing?

BTW you could get rid of all the GetBytes/GetString calls if you used
StringBuilder as the parameter type instead of byte[].
[DllImport("MMGPS", EntryPoint = "PNT1_TO_AV", ExactSpelling = true, CharSet
= CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void PNT1_TO_AV(


The calling convention is wrong, it should be Stdcall. The return type
should be int, not void. And you can remove the unsafe keyword, it's
not needed.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
Hi Mattias,

The enc is a System.Text.ASCIIEncoder.

Andrew
"Mattias Sjögren" wrote:
The Dll Code get the striings okay, proceeds with the processing and updats
them in the dll with the returned version. But when the data gets brought
back to the calling program, it appears that the C# code is only picked up
the first char of the string: so instead of getting 190311.11, it gets 1, and
instead of 44.898 it will get 4, does anybody have any suggestions about what
is cxausing this?


What kind of encoding is the enc variable representing?

BTW you could get rid of all the GetBytes/GetString calls if you used
StringBuilder as the parameter type instead of byte[].
[DllImport("MMGPS", EntryPoint = "PNT1_TO_AV", ExactSpelling = true, CharSet
= CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void PNT1_TO_AV(


The calling convention is wrong, it should be Stdcall. The return type
should be int, not void. And you can remove the unsafe keyword, it's
not needed.
Mattias

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

Nov 17 '05 #3

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

Similar topics

3
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call...
0
by: t_developer_plus | last post by:
Hi There I've been handed an XML Web Service that I am required to use. C# can build a CLIENT (consumer) of this Web service, apparently quite nicely, with the "Add Web Reference" feature. A...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
3
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.