By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

bug when calling unmanaged code from managed code

P: n/a

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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.