473,566 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VS 2005: __clrcall error exporting DLL functions which are not __clrcall? + /clr:pure/safe question

Greetings!

Some classes that once compiled without problems on VS 2003 have now
problems on VS 2005 Beta 1. I'm talking about a __nogc class that is
exported with __declspec(dlle xport).

The compiler message is this:

VCSelectLibrary Form.cpp
...\Forms\QiFor m.h(48) : error C3395: 'TQiForm::GetDo tNetMouseButton ' :
__declspec(dlle xport) cannot be applied to a function with the __clrcall
calling convention

This is odd because I'm not using "__clrcall" anywhere in my code (at least
not explicitly). Not in the function declaration, not in the class
declaration, anywhere!

I have 2 questions then:

1st) Any reason why this could be happening? Project options, parameter that
might make all calls on a given project __clrcall, etc?

2nd) Independently of the problem: I know an exported function from a DLL
can't be guaranteed to be called from a managed site. Thus, theoretically it
can't be exported. Is this the end of the story? I mean, if I compile code
with /clr:safe or /clr:pure in order to cut the unmanaged entry points from
functions and have a complete MSIL code, I won't be able to modularize it in
DLLs?

My compilation parameters are:

("Arquivos de programas" is the portuguese version of the "Program Files"
folder) ;)

/Od /Og /Ob2 /Oi /Ot /I "C:\Arquivo s de programas\Micro soft Visual Studio
..NET 2003\Vc7\Platfo rmSDK\Include" /I "." /I ".." /I "..\..\Libbuild er" /I
"..\..\Persiste nce" /I "..\..\QiReport Builder" /I
"..\..\Controls .NET\QiControls " /AI "..\VCRLibD ll" /D "WIN32" /D "NDEBUG" /D
"_WINDOWS" /D "_USRDLL" /D "QIVFORMS_EXPOR TS" /D "VISUAL_C" /D "NULL=0" /D
"_USE_MATH_DEFI NES" /D "__TRACE" /D "_WINDLL" /D "_MBCS" /FD /EHa /MD /GS
/GR /Fo"..\VCRObj/" /Fd"..\VCRObj/vc80.pdb" /W3 /nologo /c /Wp64 /Zi
/clr:oldSyntax /TP /wd4290 /wd4251 /wd4275 /wd4311 /wd4800 /FU
"QiVControls.dl l" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ Microsoft.Visua lC.Dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ mscorlib.dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Data.dll " /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Design.d ll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Drawing. dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Windows. Forms.dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.XML.dll"

Thanks,
Fabro
Nov 17 '05 #1
7 2613
1) __clrcall is implicit for managed types (__nogc and __gc) classes.
__declspec(dlle xport) does not apply to managed types. Hence, it is now
disallowed.
2) I am not sure I understand your question here. As long as your type is
not a managed type and you don't explicitly specify __clrcall, you should be
able to export it

Thx,


--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.c om/info/cpyright.htm"
"Gustavo L. Fabro" <gu************ ************@ho tmail.com> wrote in message
news:36******** *****@individua l.net...
Greetings!

Some classes that once compiled without problems on VS 2003 have now
problems on VS 2005 Beta 1. I'm talking about a __nogc class that is
exported with __declspec(dlle xport).

The compiler message is this:

VCSelectLibrary Form.cpp
..\Forms\QiForm .h(48) : error C3395: 'TQiForm::GetDo tNetMouseButton ' :
__declspec(dlle xport) cannot be applied to a function with the __clrcall
calling convention

This is odd because I'm not using "__clrcall" anywhere in my code (at
least not explicitly). Not in the function declaration, not in the class
declaration, anywhere!

I have 2 questions then:

1st) Any reason why this could be happening? Project options, parameter
that might make all calls on a given project __clrcall, etc?

2nd) Independently of the problem: I know an exported function from a DLL
can't be guaranteed to be called from a managed site. Thus, theoretically
it can't be exported. Is this the end of the story? I mean, if I compile
code with /clr:safe or /clr:pure in order to cut the unmanaged entry
points from functions and have a complete MSIL code, I won't be able to
modularize it in DLLs?

My compilation parameters are:

("Arquivos de programas" is the portuguese version of the "Program Files"
folder) ;)

/Od /Og /Ob2 /Oi /Ot /I "C:\Arquivo s de programas\Micro soft Visual Studio
.NET 2003\Vc7\Platfo rmSDK\Include" /I "." /I ".." /I "..\..\Libbuild er" /I
"..\..\Persiste nce" /I "..\..\QiReport Builder" /I
"..\..\Controls .NET\QiControls " /AI "..\VCRLibD ll" /D "WIN32" /D "NDEBUG"
/D "_WINDOWS" /D "_USRDLL" /D "QIVFORMS_EXPOR TS" /D "VISUAL_C" /D "NULL=0"
/D "_USE_MATH_DEFI NES" /D "__TRACE" /D "_WINDLL" /D "_MBCS" /FD /EHa /MD
/GS /GR /Fo"..\VCRObj/" /Fd"..\VCRObj/vc80.pdb" /W3 /nologo /c /Wp64 /Zi
/clr:oldSyntax /TP /wd4290 /wd4251 /wd4275 /wd4311 /wd4800 /FU
"QiVControls.dl l" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ Microsoft.Visua lC.Dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ mscorlib.dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Data.dll " /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Design.d ll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Drawing. dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.Windows. Forms.dll" /FU
"c:\WINXP\Micro soft.NET\Framew ork\v2.0.40607\ System.XML.dll"

Thanks,
Fabro

Nov 17 '05 #2
Hi there!
1) __clrcall is implicit for managed types (__nogc and __gc) classes.
__declspec(dll export) does not apply to managed types. Hence, it is now
disallowed.
Hmmm Let me get this straight:

You said "managed types (__nogc and __gc) classes". Don't you mean managed
code?

As far as I knew (please clear up my mess, if that's the case), a __nogc
keyword "Explicitly declares an unmanaged type."
(http://msdn.microsoft.com/library/de...clrf__nogc.asp)

Still from the help,
"Objects of this type are similar to standard C++ objects in that they are
allocated from the standard C++ heap and are not subject to the restrictions
of a managed object"

This is one of the restrictions (not being able to export). In that case
(with the __nogc keyword), it wouldn't have the restriction. Right?
2) I am not sure I understand your question here. As long as your type is
not a managed type and you don't explicitly specify __clrcall, you should
be able to export it.


I should be able to export it even if It's an unmanaged type running on a
managed code (because it was compiled with /clr)?

My question was for managed types. It's a design question:

Suppose I want to write a 100% C++/CLI code, using only .NET, MSIL and not a
line of native code.

In this particular scenario, by the information I'm having, I cannot use
__declspec(dlle xport) to export a function from a DLL. Does this means DLLs
do not exist on .NET Framework World? Because what would be the point of
having a DLL if I couldn't acess any of its functions? :)

Thanks for the attention,

Fabro
Nov 17 '05 #3
1) Sorry. I meant gc classes (value and ref types (in new syntax)) have
implicit clrcall calling convention and hence cannot use dllexport. I don't
see this behavior on __nogc classes (unmanaged types) on Beta 1. Do you
have a small snippet of code which throws this error?

2) Managed code in assemblies can be exposed by simply declaring them
public. The user of the assembly can add a reference to the dll by using
either #using syntax, by using the /FU compiler switch to force a reference
etc.,

Thx,

--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.c om/info/cpyright.htm"
"Gustavo L. Fabro" <gu************ ************@ho tmail.com> wrote in message
news:36******** *****@individua l.net...
Hi there!
1) __clrcall is implicit for managed types (__nogc and __gc) classes.
__declspec(dl lexport) does not apply to managed types. Hence, it is now
disallowed.


Hmmm Let me get this straight:

You said "managed types (__nogc and __gc) classes". Don't you mean managed
code?

As far as I knew (please clear up my mess, if that's the case), a __nogc
keyword "Explicitly declares an unmanaged type."
(http://msdn.microsoft.com/library/de...clrf__nogc.asp)

Still from the help,
"Objects of this type are similar to standard C++ objects in that they are
allocated from the standard C++ heap and are not subject to the
restrictions of a managed object"

This is one of the restrictions (not being able to export). In that case
(with the __nogc keyword), it wouldn't have the restriction. Right?
2) I am not sure I understand your question here. As long as your type is
not a managed type and you don't explicitly specify __clrcall, you should
be able to export it.


I should be able to export it even if It's an unmanaged type running on a
managed code (because it was compiled with /clr)?

My question was for managed types. It's a design question:

Suppose I want to write a 100% C++/CLI code, using only .NET, MSIL and not
a line of native code.

In this particular scenario, by the information I'm having, I cannot use
__declspec(dlle xport) to export a function from a DLL. Does this means
DLLs do not exist on .NET Framework World? Because what would be the point
of having a DLL if I couldn't acess any of its functions? :)

Thanks for the attention,

Fabro

Nov 17 '05 #4
Hi there! Thanks for the replies!

Answering backwards...

2) Managed code in assemblies can be exposed by simply declaring them
public. The user of the assembly can add a reference to the dll by using
either #using syntax, by using the /FU compiler switch to force a reference
etc.,

Great! I searched for the keywords and now things are much clearer.

1) Sorry. I meant gc classes (value and ref types (in new syntax)) have
implicit clrcall calling convention and hence cannot use dllexport. I don't
see this behavior on __nogc classes (unmanaged types) on Beta 1. Do you
have a small snippet of code which throws this error?

In fact I do! I searched my class and found the offending code!
A code like this will compile on 2003 without problems but will fail to
compile on 2005 with C3395:

Instructions:

- add a reference to System.Windows. Forms.dll (.NET 1.1.4322 on VS 2003 and
2.0.40607 on VS 2005 B1)
- compile with /clr:oldSyntax

class __declspec(dlle xport) TestClass
{
public:

TestClass();

int GetDotNetMouseB utton(
System::Windows ::Forms::MouseB uttons button
);

};

Could this be happening because I'm using a .NET type,
System::Windows ::Forms::MouseB uttons, on my theoretically __nogc class? As
my unmanaged class is trying to access a managed type, the compiler makes it
managed?

If this is the case (I think it is), how did this work back in VS 2003? ;-)

Thanx
Nov 17 '05 #5


--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.c om/info/cpyright.htm"

"Gustavo L. Fabro" <gu************ ************@ho tmail.com> wrote in message
news:36******** *****@individua l.net...
Hi there! Thanks for the replies!

Answering backwards...

2) Managed code in assemblies can be exposed by simply declaring them
public. The user of the assembly can add a reference to the dll by using
either #using syntax, by using the /FU compiler switch to force a
reference
etc.,

Great! I searched for the keywords and now things are much clearer.

1) Sorry. I meant gc classes (value and ref types (in new syntax)) have
implicit clrcall calling convention and hence cannot use dllexport. I
don't
see this behavior on __nogc classes (unmanaged types) on Beta 1. Do you
have a small snippet of code which throws this error?

In fact I do! I searched my class and found the offending code!
A code like this will compile on 2003 without problems but will fail to
compile on 2005 with C3395:

Instructions:

- add a reference to System.Windows. Forms.dll (.NET 1.1.4322 on VS 2003
and 2.0.40607 on VS 2005 B1)
- compile with /clr:oldSyntax

class __declspec(dlle xport) TestClass
{
public:

TestClass();

int GetDotNetMouseB utton(
System::Windows ::Forms::MouseB uttons button
);

};

Could this be happening because I'm using a .NET type,
System::Windows ::Forms::MouseB uttons, on my theoretically __nogc class? As
my unmanaged class is trying to access a managed type, the compiler makes
it managed?

If this is the case (I think it is), how did this work back in VS 2003?
;-)

Thanx




Hi Gustavo,
Thanks for the repro. First to answer your question, we currently dont allow
a native class member function which takes an argument of a manged type if
you try to export the class or member functions. It would work if you dont
export the class. Let me try to explain why.

When you have dllexport on your class or members, you create an entry in the
import virtual table. When a call is made to that function, it goes through
the IVT. In the case of a native function, we create a thunk to convert the
native call to a MSIL. For example, if you native function took char* as an
argument, we could convert it to String which is the equivalent managed
transformation.

In your example however, the function was "managed" and thus it had a
__clrcall calling convention. We could not do the thunking in this case and
thus the call failed.
Hope it helps. I know that thunking is not very well documented yet but I
will try to find some docs and post them.

Thanks,
Kapil


Nov 17 '05 #6
Also check out the following site:
http://msdn2.microsoft.com/library/eyzhw3s8.aspx

It contains some good articles on native/managed transitions.
Thanks.

--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.c om/info/cpyright.htm"

"Kapil Khosla [MSFTt]" <kk*****@online .microsoft.com> wrote in message
news:eO******** ******@TK2MSFTN GP15.phx.gbl...


--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified
at
http://www.microsoft.c om/info/cpyright.htm"

"Gustavo L. Fabro" <gu************ ************@ho tmail.com> wrote in
message news:36******** *****@individua l.net...
Hi there! Thanks for the replies!

Answering backwards...

2) Managed code in assemblies can be exposed by simply declaring them
public. The user of the assembly can add a reference to the dll by using
either #using syntax, by using the /FU compiler switch to force a
reference
etc.,

Great! I searched for the keywords and now things are much clearer.

1) Sorry. I meant gc classes (value and ref types (in new syntax)) have
implicit clrcall calling convention and hence cannot use dllexport. I
don't
see this behavior on __nogc classes (unmanaged types) on Beta 1. Do you
have a small snippet of code which throws this error?

In fact I do! I searched my class and found the offending code!
A code like this will compile on 2003 without problems but will fail to
compile on 2005 with C3395:

Instructions:

- add a reference to System.Windows. Forms.dll (.NET 1.1.4322 on VS 2003
and 2.0.40607 on VS 2005 B1)
- compile with /clr:oldSyntax

class __declspec(dlle xport) TestClass
{
public:

TestClass();

int GetDotNetMouseB utton(
System::Windows ::Forms::MouseB uttons button
);

};

Could this be happening because I'm using a .NET type,
System::Windows ::Forms::MouseB uttons, on my theoretically __nogc class?
As my unmanaged class is trying to access a managed type, the compiler
makes it managed?

If this is the case (I think it is), how did this work back in VS 2003?
;-)

Thanx




Hi Gustavo,
Thanks for the repro. First to answer your question, we currently dont
allow a native class member function which takes an argument of a manged
type if you try to export the class or member functions. It would work if
you dont export the class. Let me try to explain why.

When you have dllexport on your class or members, you create an entry in
the import virtual table. When a call is made to that function, it goes
through the IVT. In the case of a native function, we create a thunk to
convert the native call to a MSIL. For example, if you native function
took char* as an argument, we could convert it to String which is the
equivalent managed transformation.

In your example however, the function was "managed" and thus it had a
__clrcall calling convention. We could not do the thunking in this case
and thus the call failed.
Hope it helps. I know that thunking is not very well documented yet but I
will try to find some docs and post them.

Thanks,
Kapil

Nov 17 '05 #7
Hi there,

Hi Gustavo,
Thanks for the repro. First to answer your question, we currently dont
allow a native class member function which takes an argument of a manged
type if you try to export the class or member functions. It would work if
you dont export the class. Let me try to explain why.

When you have dllexport on your class or members, you create an entry in
the import virtual table. When a call is made to that function, it goes
through the IVT. In the case of a native function, we create a thunk to
convert the native call to a MSIL. For example, if you native function
took char* as an argument, we could convert it to String which is the
equivalent managed transformation.

In your example however, the function was "managed" and thus it had a
__clrcall calling convention. We could not do the thunking in this case
and thus the call failed.
Hope it helps. I know that thunking is not very well documented yet but I
will try to find some docs and post them.


It took me a while to reply because we were at carnival here in Brazil...
;-)

Thanx for the explanation and the URL to the docs. I'll definitely read
them.

Best regards,
Fabro
Nov 17 '05 #8

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

Similar topics

12
3554
by: Herby | last post by:
Hi, I am currently reviewing what is required to convert a current MFC, COM server application into a .NET application. The objective is to compile ultimately to clr/safe. So we are seeking a clear migration path for C++\MFC\COM to .NET. We have now chosen to select C++\CLI. We then need to remove the MFC classes such as CString...
8
2177
by: Gary Nastrasio | last post by:
If I compile with /clr:safe, which is exactly meant by saying I can't use "Native Types" in my code? Is a native type something such as float, short, or int? Thanks, Gary
2
1425
by: C.O.Jones | last post by:
I've previously used version 7 and 2000. I've recently started to learn ASP.net. I've installed Visual Web Developer 2005 Express and this includes SQLServer 2005 in the installation. The task manager and and the list of services definitely show I've got SQLServer running on my computer. Here's the problem: how do I actually use it? I...
1
1154
by: Nick | last post by:
I tried to use the following code in MS VS .Net 2003 VS C++ #using <mscorlib.dll> using namespace System; but i get fatal error C1190: managed targeted code requires '#using <mscorlib.dll>' and '/clr' option. i dont know where to put the /clr option. please help! Thank you!
1
1424
by: steve02a | last post by:
I'm attempting to export data from a datagrid. I'm successful at exporting it in xls, doc, html types - but csv and pdf are giving me a headache. The code I'm using isn't anything fancy: Response.ContentType="application/pdf"; Response.AddHeader("content-disposition","fileattachment;filename=whatever.pdf");...
5
1451
by: Bart | last post by:
Hi, What is the benefit of using the Pure option over the Mixed one. Is there a better performance? We have a lot of stuff in c++ with mfc support en we want to use in our .net apps. With mixed setting we can compile including the mfc part of our code. We can get rid of the mfc code but it will cost us some effort so we can use the pure...
13
3634
by: =?Utf-8?B?d3BjbWFtZQ==?= | last post by:
I have a small C++/CLI application which calls an unmanaged lib. It seems like I can't use /clr:pure and link with the unmanaged lib (LNK1313 error). The problem I have is that compiling with /clr adds a dependency on several msvc*.dll:s which adds some unwanted complexity to the installation. Is it possible to avoid the msvc*.dll...
1
1547
by: ajk | last post by:
Hi I am doing a C++/CLI dll that is supposed to be fully managed code. I was wondering what exactly is the criteria for the DLL to be 100% fully managed and usuable from C#? Do I need to compile using / clr:safe or is /clr enough? The reason I need to know this is that I would like to use pin_ptr<> for some type conversions i.e. bytes to...
0
7666
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...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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. ...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
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...
0
7951
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
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...
1
2083
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
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.