473,669 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass a structure by reference to C++ dll in .Net Compact Framework

I'm trying to pass a structer from C# to a C dll in .Net Compact Framework

This partially works. If in the GetStatus I only set -- status->fileLength
= 10; -- and not the second variable then filelength = 10 and fileposition =
0, but if i set the second one only or both of them then they are fileLength
= 47244640266 and filePosition = 0; Like the memory is getting over wrote.
What is the correct way of passing a structure by reference on the Compact
Framework.

here is my code

In the C dll
-------------------------------------------

----------------in the header
struct FileStatus
{
long fileLength;
long filePosition;
};

extern "C" __declspec(dlle xport) bool GetStatus (FileStatus* status);
----------------

---------------in the cpp
bool GetStatus (FileStatus* status)
{
status->fileLength = 10;
status->filePosition = 11;
return true;
}
--------------------------------------------

int my C# code i have
--------------------------------------------
namespace Controls
{
[StructLayout(La youtKind.Sequen tial)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplor er
{

[DllImport("Test Dll.dll", EntryPoint="Get Status")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}
------------------------------------------

Any Ideas

thanks
Nov 15 '05 #1
2 6645
since when a long in C is 8 bytes long ?
maybe on windows 64, but certainly not on PPC, or so I assume....

I would rather write:
[StructLayout(La youtKind.Sequen tial)]
public struct SStatus
{
public int fileLength;
public int filePosition;
}

"Maloney" <sa*******@soft home.net> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...
I'm trying to pass a structer from C# to a C dll in .Net Compact Framework

This partially works. If in the GetStatus I only set -- status->fileLength = 10; -- and not the second variable then filelength = 10 and fileposition = 0, but if i set the second one only or both of them then they are fileLength = 47244640266 and filePosition = 0; Like the memory is getting over wrote. What is the correct way of passing a structure by reference on the Compact
Framework.

here is my code

In the C dll
-------------------------------------------

----------------in the header
struct FileStatus
{
long fileLength;
long filePosition;
};

extern "C" __declspec(dlle xport) bool GetStatus (FileStatus* status);
----------------

---------------in the cpp
bool GetStatus (FileStatus* status)
{
status->fileLength = 10;
status->filePosition = 11;
return true;
}
--------------------------------------------

int my C# code i have
--------------------------------------------
namespace Controls
{
[StructLayout(La youtKind.Sequen tial)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplor er
{

[DllImport("Test Dll.dll", EntryPoint="Get Status")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}
------------------------------------------

Any Ideas

thanks

Nov 15 '05 #2
FYI:
here is the whole story, I believe:
C:
char: 1 bytes
short: 2 bytes
long: 4 bytes
long long (gcc): 8 bytes
int: size of register (4 on PPC)

C#:
int: 4 bytes
long: 8 bytes
see ?

"Maloney" <sa*******@soft home.net> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...
I'm trying to pass a structer from C# to a C dll in .Net Compact Framework

This partially works. If in the GetStatus I only set -- status->fileLength = 10; -- and not the second variable then filelength = 10 and fileposition = 0, but if i set the second one only or both of them then they are fileLength = 47244640266 and filePosition = 0; Like the memory is getting over wrote. What is the correct way of passing a structure by reference on the Compact
Framework.

here is my code

In the C dll
-------------------------------------------

----------------in the header
struct FileStatus
{
long fileLength;
long filePosition;
};

extern "C" __declspec(dlle xport) bool GetStatus (FileStatus* status);
----------------

---------------in the cpp
bool GetStatus (FileStatus* status)
{
status->fileLength = 10;
status->filePosition = 11;
return true;
}
--------------------------------------------

int my C# code i have
--------------------------------------------
namespace Controls
{
[StructLayout(La youtKind.Sequen tial)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplor er
{

[DllImport("Test Dll.dll", EntryPoint="Get Status")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}
------------------------------------------

Any Ideas

thanks

Nov 15 '05 #3

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

Similar topics

1
4962
by: boble | last post by:
Sorry, it's may be off topic ;_((( The following article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k3/ht ml/winmob03.asp states that a.. Microsoft Windows .NET Compact Framework-The .NET Compact Framework is in ROM in all new Pocket PC 2003 devices, and can be installed in RAM in Pocket PC 2000 and Pocket PC 2002 devices. The question is: how? Answers would be greatly appreciated
0
2598
by: Earle Oxner | last post by:
We are developing an application on PocketPC2002 platform and we are trying to make webservice calls using HTTPS. HTTP works fine but HTTPS does not work. The same code which doesn't work on PocketPC, works on the laptop with .NET Framework. I was hoping you could help me with answering some questions: 1. Does HTTPS work for the System.Net.WebRequest.Create (sURL), GetRequestStream, System.IO.StreamWriter library calls we are making...
2
2855
by: Duncan | last post by:
I am using the evaluation version of CE.NET 4.1. I had also installed the release version of the Compact Framework. I uninstalled the CE.NET 4.1, and then realized I needed it again and reinstalled it. I also installed all the QFEs. When I tried to reinstall the release Compact Framework, I get a message that it is already installed and the installation aborted.
1
2514
by: Asad Khan | last post by:
Hi, I have Visual Studio 2002 Enterprise Architecture Edition. I was wondering if anyone has any information on how I can develop applications for .Net Compact Framework using this IDE. I've heard Visual Studio 2003 ships with the functionality for .Net Compact Framework development. But right now I have Visual Studio 2002. Is there anything I can do? (Other than the obvious upgrade to 2003). I've heard some beta version of .Net Compact...
3
3643
by: Panda2 | last post by:
Say I have a structure such as: struct Barn{ char type; int number; }animal so for example we might have data like animal.type cow animal.number 10
7
3890
by: TJ | last post by:
In C# how do you achieve pass-by-reference property declarations in the Type Library? I am writing a COM Class Library that must mimick an existing library for which the only information is the TypeLib. I'm using Visual Studio .NET 2003. The original library provides simple authentication services, from Access and MS-SQL OLEDB providers. The enhancement I'm creating provides support for ODBC and will be a drop-in replacement.
5
3334
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a way of converting a project to have builds for both compact and full. Project properties doesn't seem to help Thanks
0
1369
by: paulodonnell99 | last post by:
Hi, I am trying to build an installer application to run on the compact framework, I want to produce a netmodule using CSC.exe, then use AL.exe to embed resouce files and produce an exe. My problem is, when I use CSC.exe to produce my netmodule it keeps throwing in an extra reference to mscorlib - such that when the netmodule is opened with Ildasm the assembly manifest looks like this:
3
2619
by: Greg | last post by:
Hello all, I am looking to download an image from a website from within a compact framework pda app. I have tried everything I could find and thus I turn to you. Any help or suggestions would be appreciated. Thank you.
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8588
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.