473,399 Members | 3,919 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,399 software developers and data experts.

PInvoke with return type long problem

I'm trying to call some unmanaged methods from a DLL. I did this awhile
ago, a couple years ago... I'm a little rusty. I will show you what I'm
dealing with:

<unmanaged function signature>
STATUS_T WINAPI MSP430_Initialize(CHAR* port, LONG* version);

</unmanaged function signature>

STATUS_T is a long (typedef long STATUS_T)
CHAR is a char (winnt.h)
LONG is a long(winnt.h)

Here is my c# signature:
<c# signature>
[DllImport("MSP430.dll")]

static extern long MSP430_Initialize(string port, out long version);

</c# signature>

This doesn't crash (it did before I added the 'out' keyword) but it also
doesn't return a valid value. If I make the same call from a unmanaged c
app I get a return result of: 0
In my c# app I get: 8589934592
I'm not seeing the problem. I know PInvoke can be a tricky bastard... but
this seems pretty straightforward. Anyone have any ideas for me?

Thanks for reading,
Steve
Feb 24 '06 #1
3 4079
weird. I found that if I changed the return type to an int in the managed
code it works fine.

static extern int MSP430_Initialize(string port, out long version);
Anyone know why?

"Steve" <ss*@sss.com> wrote in message
news:eZ**************@TK2MSFTNGP12.phx.gbl...
I'm trying to call some unmanaged methods from a DLL. I did this awhile
ago, a couple years ago... I'm a little rusty. I will show you what I'm
dealing with:

<unmanaged function signature>
STATUS_T WINAPI MSP430_Initialize(CHAR* port, LONG* version);

</unmanaged function signature>

STATUS_T is a long (typedef long STATUS_T)
CHAR is a char (winnt.h)
LONG is a long(winnt.h)

Here is my c# signature:
<c# signature>
[DllImport("MSP430.dll")]

static extern long MSP430_Initialize(string port, out long version);

</c# signature>

This doesn't crash (it did before I added the 'out' keyword) but it also
doesn't return a valid value. If I make the same call from a unmanaged c
app I get a return result of: 0
In my c# app I get: 8589934592
I'm not seeing the problem. I know PInvoke can be a tricky bastard... but
this seems pretty straightforward. Anyone have any ideas for me?

Thanks for reading,
Steve

Feb 24 '06 #2
because a int in C# is equivilent to a long in C++.
an int16 is equivlent to a short in C++.

Cheers,
Mark

"Steve" wrote:
weird. I found that if I changed the return type to an int in the managed
code it works fine.

static extern int MSP430_Initialize(string port, out long version);
Anyone know why?

"Steve" <ss*@sss.com> wrote in message
news:eZ**************@TK2MSFTNGP12.phx.gbl...
I'm trying to call some unmanaged methods from a DLL. I did this awhile
ago, a couple years ago... I'm a little rusty. I will show you what I'm
dealing with:

<unmanaged function signature>
STATUS_T WINAPI MSP430_Initialize(CHAR* port, LONG* version);

</unmanaged function signature>

STATUS_T is a long (typedef long STATUS_T)
CHAR is a char (winnt.h)
LONG is a long(winnt.h)

Here is my c# signature:
<c# signature>
[DllImport("MSP430.dll")]

static extern long MSP430_Initialize(string port, out long version);

</c# signature>

This doesn't crash (it did before I added the 'out' keyword) but it also
doesn't return a valid value. If I make the same call from a unmanaged c
app I get a return result of: 0
In my c# app I get: 8589934592
I'm not seeing the problem. I know PInvoke can be a tricky bastard... but
this seems pretty straightforward. Anyone have any ideas for me?

Thanks for reading,
Steve


Feb 24 '06 #3
Thanks Mark, I should have known that :0)

Have a good weekend,
Steve
"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
because a int in C# is equivilent to a long in C++.
an int16 is equivlent to a short in C++.

Cheers,
Mark

"Steve" wrote:
weird. I found that if I changed the return type to an int in the
managed
code it works fine.

static extern int MSP430_Initialize(string port, out long version);
Anyone know why?

"Steve" <ss*@sss.com> wrote in message
news:eZ**************@TK2MSFTNGP12.phx.gbl...
> I'm trying to call some unmanaged methods from a DLL. I did this
> awhile
> ago, a couple years ago... I'm a little rusty. I will show you what
> I'm
> dealing with:
>
> <unmanaged function signature>
> STATUS_T WINAPI MSP430_Initialize(CHAR* port, LONG* version);
>
> </unmanaged function signature>
>
> STATUS_T is a long (typedef long STATUS_T)
> CHAR is a char (winnt.h)
> LONG is a long(winnt.h)
>
> Here is my c# signature:
> <c# signature>
> [DllImport("MSP430.dll")]
>
> static extern long MSP430_Initialize(string port, out long version);
>
> </c# signature>
>
> This doesn't crash (it did before I added the 'out' keyword) but it
> also
> doesn't return a valid value. If I make the same call from a unmanaged
> c
> app I get a return result of: 0
> In my c# app I get: 8589934592
>
>
> I'm not seeing the problem. I know PInvoke can be a tricky bastard...
> but
> this seems pretty straightforward. Anyone have any ideas for me?
>
> Thanks for reading,
> Steve
>


Feb 24 '06 #4

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

Similar topics

0
by: vijaya | last post by:
I've a problem with PInvoke.I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.Please apologise for this lenghty message and render ur kind help. The original dll...
5
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD...
0
by: theta | last post by:
Hi everyone. I'm a .NET newbie and I have a problem calling DLL functions from vb .net. I'm trying to access Howl's Rendezvous.dll (www.porchdogsoft.com/products/howl/) from managed code. I was...
0
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
0
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
3
by: msnews.microsoft.com | last post by:
Hi i am using User32.dll in Visual stdio 2005. public static extern long SetActiveWindow(long hwnd); public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
6
by: Pucca | last post by:
I have a program that originally compiles into a exe file. I changed the compile option to generate dll file. This program calls a com component. Can I use pinvoke in C# to call it? The...
1
by: gregarican | last post by:
A couple of days ago I was debating about whether to use C++/CLI or C# 2005's PInvoke in order to tie in my VS 2005 app with a legacy csta32.dll file. So far I have tried to call one method out of...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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...
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...
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...

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.