473,465 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

bug when calling unmanaged code from managed code


This seems incredibale to me but I've done some testing and it appears I
can't pass in a long and than an int to a function. The int is not passed in
correctly.

[DllImport("ravenCore.dll")] extern static int rvCore_bl_get_schedule(long
driverNum, int nList);
When I call rvCore_bl_get_schedule(long driverNum, int nList) with a value
in driverNum and nList, nList is 0 in my unmanaged code.

If I change my parameters to be both long or both int it works fine.

Any comments on why something so simple is so screwy?


Nov 16 '05 #1
4 1263
Ed,

Does the definition in unmanaged code call for a long and an int? If
so, then this could be your problem. In unmanaged C++ environments, a long
and an int both represent signed 32 bit integers. In .NET, a long is a
signed 64-bit integer. This is probably what is throwing it off.

Change the driverNum parameter to an integer and it should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ed Debrot" <de****@addsys.com> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...

This seems incredibale to me but I've done some testing and it appears I
can't pass in a long and than an int to a function. The int is not passed
in
correctly.

[DllImport("ravenCore.dll")] extern static int rvCore_bl_get_schedule(long
driverNum, int nList);
When I call rvCore_bl_get_schedule(long driverNum, int nList) with a value
in driverNum and nList, nList is 0 in my unmanaged code.

If I change my parameters to be both long or both int it works fine.

Any comments on why something so simple is so screwy?

Nov 16 '05 #2
What is the unmanaged code definition (in C++)

#ifdef RAVENCORE_EXPORTS
#define RAVENCORE_API __declspec(dllexport)
#else
#define RAVENCORE_API __declspec(dllimport)
#endif

extern "C"
{
RAVENCORE_API int rvCore_bl_get_schedule(long driverNum, int nList);
}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O4**************@TK2MSFTNGP15.phx.gbl... Ed,

Does the definition in unmanaged code call for a long and an int? If
so, then this could be your problem. In unmanaged C++ environments, a long and an int both represent signed 32 bit integers. In .NET, a long is a
signed 64-bit integer. This is probably what is throwing it off.

Change the driverNum parameter to an integer and it should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ed Debrot" <de****@addsys.com> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...

This seems incredibale to me but I've done some testing and it appears I
can't pass in a long and than an int to a function. The int is not passed in
correctly.

[DllImport("ravenCore.dll")] extern static int rvCore_bl_get_schedule(long driverNum, int nList);
When I call rvCore_bl_get_schedule(long driverNum, int nList) with a value in driverNum and nList, nList is 0 in my unmanaged code.

If I change my parameters to be both long or both int it works fine.

Any comments on why something so simple is so screwy?


Nov 16 '05 #3
Ed,

I think you posted some of the offline conversation between us =)

Basically, your unmanaged code declaration is wrong, the driverNum
parameter needs to be declared as an int.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ed Debrot" <de****@addsys.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
What is the unmanaged code definition (in C++)

#ifdef RAVENCORE_EXPORTS
#define RAVENCORE_API __declspec(dllexport)
#else
#define RAVENCORE_API __declspec(dllimport)
#endif

extern "C"
{
RAVENCORE_API int rvCore_bl_get_schedule(long driverNum, int nList);
}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:O4**************@TK2MSFTNGP15.phx.gbl...
Ed,

Does the definition in unmanaged code call for a long and an int? If
so, then this could be your problem. In unmanaged C++ environments, a

long
and an int both represent signed 32 bit integers. In .NET, a long is a
signed 64-bit integer. This is probably what is throwing it off.

Change the driverNum parameter to an integer and it should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ed Debrot" <de****@addsys.com> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...
>
> This seems incredibale to me but I've done some testing and it appears
> I
> can't pass in a long and than an int to a function. The int is not passed > in
> correctly.
>
> [DllImport("ravenCore.dll")] extern static int rvCore_bl_get_schedule(long > driverNum, int nList);
> When I call rvCore_bl_get_schedule(long driverNum, int nList) with a value > in driverNum and nList, nList is 0 in my unmanaged code.
>
> If I change my parameters to be both long or both int it works fine.
>
> Any comments on why something so simple is so screwy?
>
>
>
>



Nov 16 '05 #4
C long is 32-bit, which is int in C#

"Ed Debrot" wrote:

This seems incredibale to me but I've done some testing and it appears I
can't pass in a long and than an int to a function. The int is not passed in
correctly.

[DllImport("ravenCore.dll")] extern static int rvCore_bl_get_schedule(long
driverNum, int nList);
When I call rvCore_bl_get_schedule(long driverNum, int nList) with a value
in driverNum and nList, nList is 0 in my unmanaged code.

If I change my parameters to be both long or both int it works fine.

Any comments on why something so simple is so screwy?


Nov 16 '05 #5

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

Similar topics

4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
3
by: Jacob Gladish | last post by:
In the following code snippet, I am calling into an unmanaged static .lib file from a managed class. I belive that I have to pin the pointer before making the call into the unmanaged code, but I...
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...
0
by: sklett | last post by:
I'm having a really hard time with wrapping an unmanaged class with a managed class, then calling that managed class from my C# code. I will show you the three pieces, then explain: --------...
10
by: Gustavo L. Fabro | last post by:
Greetings! I've been porting an application for Builder to VS .NET 2003 and searching for possible bottlenecks (the application is currently running slow). I found out one scenario that takes a...
1
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender,...
1
by: MC-Advantica | last post by:
Does anyone have a simple "Hello World" like application that demonstrates unmanaged C++ calling managed C++ developed in VS2005? I'm confused by many posts as they discuss managed extensions from...
1
by: Arne Adams | last post by:
Hi, I try to use a C# Dialog in a legacy MFC application. The problem seems to boil down to the following: from an unmanaged console application I can call any function of the managed bridge - if...
7
by: =?Utf-8?B?U3RldmVa?= | last post by:
First off, I am not sure if this belongs in this group or the C# group. It seems more like a C++ problem to me. Anyways... I have a C# project which links in an unmanaged C++ DLL, both built...
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
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.