473,657 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DllImportAttrib ute CallingConventi on

I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
CallingConventi on=CallingConve ntion.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConventi on of ThisCall, its just
normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are
NOT set, yet with ThisCall, they are set ok, or appear to be. I find it odd.

Thanks
Nov 15 '05 #1
12 2151
Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
CallingConventi on=CallingConve ntion.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConventi on of ThisCall, its just
normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are
NOT set, yet with ThisCall, they are set ok, or appear to be. I find it odd.
Thanks

Nov 15 '05 #2
Nop, I tried ref and it doesnt help, the only way i can get it to return
values is with thiscall.

"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
CallingConventi on=CallingConve ntion.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConventi on of ThisCall, its just normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are NOT set, yet with ThisCall, they are set ok, or appear to be. I find it

odd.

Thanks


Nov 15 '05 #3
So i should use Int32 for the parameters instead of long?
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
CallingConventi on=CallingConve ntion.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConventi on of ThisCall, its just normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are NOT set, yet with ThisCall, they are set ok, or appear to be. I find it

odd.

Thanks


Nov 15 '05 #4
I also have a problem with "ref" paramaters, it says they need to be
assigned to before used

Yet i have them used as "ref" in dll extern calls and checked for non NULL
after yet it complains for non assignment so i use a local copy.

Isnt it smart enough to detect that its being assinged in an extern dll call
as declared in DllImport?


"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
CallingConventi on=CallingConve ntion.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConventi on of ThisCall, its just normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are NOT set, yet with ThisCall, they are set ok, or appear to be. I find it

odd.

Thanks


Nov 15 '05 #5
i mean "out" oops.

ref in the same dll wrapper still gets the output but only with thiscall
convention.
"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
I also have a problem with "ref" paramaters, it says they need to be
assigned to before used

Yet i have them used as "ref" in dll extern calls and checked for non NULL
after yet it complains for non assignment so i use a local copy.

Isnt it smart enough to detect that its being assinged in an extern dll call as declared in DllImport?


"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
CallingConventi on=CallingConve ntion.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConventi on of ThisCall, its just normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are NOT set, yet with ThisCall, they are set ok, or appear to be. I find
it odd.

Thanks



Nov 15 '05 #6
If you could post the original function declaration, it would help
tremendously.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:e6******** ******@TK2MSFTN GP09.phx.gbl...
i mean "out" oops.

ref in the same dll wrapper still gets the output but only with thiscall
convention.
"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
I also have a problem with "ref" paramaters, it says they need to be
assigned to before used

Yet i have them used as "ref" in dll extern calls and checked for non NULL
after yet it complains for non assignment so i use a local copy.

Isnt it smart enough to detect that its being assinged in an extern dll

call
as declared in DllImport?


"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>

wrote
in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out. Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
> I am calling an unmanaged DLL like follows in a Class wrapper.
>
> namespace blah
> {
> [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
> CallingConventi on=CallingConve ntion.ThisCall]
> public static extern void blahFn(out long blah, out long blah2);
>
> class sealed ClassBlah
> {
> private ClassBlah()
> {
> }
>
> }
> }
>
> Why have I to call this with the CallingConventi on of ThisCall, its

just
> normal "C" functions in a DLL. Why wont StdCall work?
>
> What happens with other calling conventions is that the out
parameters are
> NOT set, yet with ThisCall, they are set ok, or appear to be. I find

it odd.
>
>
>
> Thanks
>
>



Nov 15 '05 #7
It would but I dont have it, its in a dll i have to call into. Not mine.


"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:OB******** ******@TK2MSFTN GP11.phx.gbl...
If you could post the original function declaration, it would help
tremendously.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:e6******** ******@TK2MSFTN GP09.phx.gbl...
i mean "out" oops.

ref in the same dll wrapper still gets the output but only with thiscall
convention.
"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
I also have a problem with "ref" paramaters, it says they need to be
assigned to before used

Yet i have them used as "ref" in dll extern calls and checked for non NULL after yet it complains for non assignment so i use a local copy.

Isnt it smart enough to detect that its being assinged in an extern dll
call
as declared in DllImport?


"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>

wrote
in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
> Mr. Tickle,
>
> What is the declaration of the original function? If it takes a
> pointer, then you should be using "ref" for the parameters, and not out. > Also, does the function take a 64-bit integer? Long in C is a
32-bit > integer, where in .NET it is a 64-bit integer.
>
> The STDCALL mechanism should work if you are using it.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - ni************* *@exisconsultin g.com
>
> "Mr.Tickle" <Mr******@mrmen .com> wrote in message
> news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
> > I am calling an unmanaged DLL like follows in a Class wrapper.
> >
> > namespace blah
> > {
> > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
> > CallingConventi on=CallingConve ntion.ThisCall]
> > public static extern void blahFn(out long blah, out long blah2);
> >
> > class sealed ClassBlah
> > {
> > private ClassBlah()
> > {
> > }
> >
> > }
> > }
> >
> > Why have I to call this with the CallingConventi on of ThisCall, its just
> > normal "C" functions in a DLL. Why wont StdCall work?
> >
> > What happens with other calling conventions is that the out parameters are
> > NOT set, yet with ThisCall, they are set ok, or appear to be. I

find it
> odd.
> >
> >
> >
> > Thanks
> >
> >
>
>



Nov 15 '05 #8
typedef SOME_ID long

SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
someIDhere3);

something like that.
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:OB******** ******@TK2MSFTN GP11.phx.gbl...
If you could post the original function declaration, it would help
tremendously.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:e6******** ******@TK2MSFTN GP09.phx.gbl...
i mean "out" oops.

ref in the same dll wrapper still gets the output but only with thiscall
convention.
"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
I also have a problem with "ref" paramaters, it says they need to be
assigned to before used

Yet i have them used as "ref" in dll extern calls and checked for non NULL after yet it complains for non assignment so i use a local copy.

Isnt it smart enough to detect that its being assinged in an extern dll
call
as declared in DllImport?


"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>

wrote
in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
> Mr. Tickle,
>
> What is the declaration of the original function? If it takes a
> pointer, then you should be using "ref" for the parameters, and not out. > Also, does the function take a 64-bit integer? Long in C is a
32-bit > integer, where in .NET it is a 64-bit integer.
>
> The STDCALL mechanism should work if you are using it.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - ni************* *@exisconsultin g.com
>
> "Mr.Tickle" <Mr******@mrmen .com> wrote in message
> news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
> > I am calling an unmanaged DLL like follows in a Class wrapper.
> >
> > namespace blah
> > {
> > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
> > CallingConventi on=CallingConve ntion.ThisCall]
> > public static extern void blahFn(out long blah, out long blah2);
> >
> > class sealed ClassBlah
> > {
> > private ClassBlah()
> > {
> > }
> >
> > }
> > }
> >
> > Why have I to call this with the CallingConventi on of ThisCall, its just
> > normal "C" functions in a DLL. Why wont StdCall work?
> >
> > What happens with other calling conventions is that the out parameters are
> > NOT set, yet with ThisCall, they are set ok, or appear to be. I

find it
> odd.
> >
> >
> >
> > Thanks
> >
> >
>
>



Nov 15 '05 #9
Mr.Tickle,

In this case, you definitely want to use the int type, and pass it by
reference. Your declaration should look like this:

[DllImport("some dll.dll")]
public static extern int someFn(ref int someIDhere, ref int someIDhere2, ref
int someIDhere3);
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
typedef SOME_ID long

SOME_ID someFn(SOME_ID* someIDhere, SOME_ID* someIDhere2, SOME_ID*
someIDhere3);

something like that.
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote in message news:OB******** ******@TK2MSFTN GP11.phx.gbl...
If you could post the original function declaration, it would help
tremendously.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:e6******** ******@TK2MSFTN GP09.phx.gbl...
i mean "out" oops.

ref in the same dll wrapper still gets the output but only with thiscall convention.
"Mr.Tickle" <Mr******@mrmen .com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
> I also have a problem with "ref" paramaters, it says they need to be
> assigned to before used
>
> Yet i have them used as "ref" in dll extern calls and checked for non
NULL
> after yet it complains for non assignment so i use a local copy.
>
> Isnt it smart enough to detect that its being assinged in an extern dll call
> as declared in DllImport?
>
>
>
>
> "Nicholas Paldino [.NET/C# MVP]"
<ni************ **@exisconsulti ng.com> wrote
> in message news:#p******** ******@TK2MSFTN GP11.phx.gbl...
> > Mr. Tickle,
> >
> > What is the declaration of the original function? If it takes a > > pointer, then you should be using "ref" for the parameters, and not
out.
> > Also, does the function take a 64-bit integer? Long in C is a

32-bit > > integer, where in .NET it is a 64-bit integer.
> >
> > The STDCALL mechanism should work if you are using it.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni************* *@exisconsultin g.com
> >
> > "Mr.Tickle" <Mr******@mrmen .com> wrote in message
> > news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
> > > I am calling an unmanaged DLL like follows in a Class wrapper.
> > >
> > > namespace blah
> > > {
> > > [DllImport("DLLN ame.DLL", EntryPoint="Bla hEntryPoint",
> > > CallingConventi on=CallingConve ntion.ThisCall]
> > > public static extern void blahFn(out long blah, out long
blah2); > > >
> > > class sealed ClassBlah
> > > {
> > > private ClassBlah()
> > > {
> > > }
> > >
> > > }
> > > }
> > >
> > > Why have I to call this with the CallingConventi on of ThisCall,

its > just
> > > normal "C" functions in a DLL. Why wont StdCall work?
> > >
> > > What happens with other calling conventions is that the out

parameters
> are
> > > NOT set, yet with ThisCall, they are set ok, or appear to be. I find it
> > odd.
> > >
> > >
> > >
> > > Thanks
> > >
> > >
> >
> >
>
>



Nov 15 '05 #10

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

Similar topics

11
2441
by: Mr.Tickle | last post by:
I am calling an unmanaged DLL like follows in a Class wrapper. namespace blah { public static extern void blahFn(out long blah, out long blah2); class sealed ClassBlah { private ClassBlah()
13
632
by: Mr.Tickle | last post by:
I am calling an unmanaged DLL like follows in a Class wrapper. namespace blah { public static extern void blahFn(out long blah, out long blah2); class sealed ClassBlah { private ClassBlah()
12
281
by: Mr.Tickle | last post by:
I am calling an unmanaged DLL like follows in a Class wrapper. namespace blah { public static extern void blahFn(out long blah, out long blah2); class sealed ClassBlah { private ClassBlah()
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
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...
1
8518
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,...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
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
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
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
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.