bug when calling unmanaged code from managed code

  • Thread starter Thread starter Ed Debrot
  • Start date Start date
E

Ed Debrot

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?
 
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.
 
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 said:
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]
- (e-mail address removed)

Ed Debrot said:
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?
 
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]
- (e-mail address removed)

Ed Debrot said:
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);
}



in
message news:[email protected]...
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]
- (e-mail address removed)

Ed Debrot said:
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?
 
Back
Top