473,809 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

/clr:pure & GetLastError

The MSDN documentation says that the GetLastError function can give
undefined behavior when compiling with /clr:pure switch. Does this statement
apply to both C++ interop and P/Invoke? If yes, does it mean that we have to
use Marshal::GetLas tWin32Error to check the last error code?
Feb 13 '07 #1
2 1764
Hi Vedo!
The MSDN documentation says that the GetLastError function can give
undefined behavior when compiling with /clr:pure switch. Does this statement
apply to both C++ interop and P/Invoke? If yes, does it mean that we have to
use Marshal::GetLas tWin32Error to check the last error code?
If you use DllImportAttrib ute, you can set "SetLastErr or" to true, this
will retrive the GetLastError value right after the call and you can use
the Marshal::GetLas tWin32Error method to query these value.

And it seems that it also works for "C++ interop":
The following code:
namespace Foo
{
ref class Bar
{
void Test()
{
TCHAR szStr[100];
DWORD dwSize = 100;
BOOL bRet = GetUserName(szS tr, &dwSize);
DWORD dw = GetLastError();
}
};
}

generates the following DllImport-Statement in VC2005:

[MethodImpl(Meth odImplOptions.U nmanaged,
MethodCodeType= MethodCodeType. Native), SuppressUnmanag edCodeSecurity,
DllImport("", EntryPoint="",
CallingConventi on=CallingConve ntion.StdCall, SetLastError=tr ue)]
public static extern unsafe int modopt(CallConv Stdcall)
GetUserNameW(ch ar*, uint modopt(IsLong)* );
Greetings
Jochen
Feb 13 '07 #2
thank you...

"Jochen Kalmbach [MVP]" <no************ ********@holzma .dewrote in message
news:OJ******** ******@TK2MSFTN GP05.phx.gbl...
Hi Vedo!
>The MSDN documentation says that the GetLastError function can give
undefined behavior when compiling with /clr:pure switch. Does this
statement apply to both C++ interop and P/Invoke? If yes, does it mean
that we have to use Marshal::GetLas tWin32Error to check the last error
code?

If you use DllImportAttrib ute, you can set "SetLastErr or" to true, this
will retrive the GetLastError value right after the call and you can use
the Marshal::GetLas tWin32Error method to query these value.

And it seems that it also works for "C++ interop":
The following code:
namespace Foo
{
ref class Bar
{
void Test()
{
TCHAR szStr[100];
DWORD dwSize = 100;
BOOL bRet = GetUserName(szS tr, &dwSize);
DWORD dw = GetLastError();
}
};
}

generates the following DllImport-Statement in VC2005:

[MethodImpl(Meth odImplOptions.U nmanaged,
MethodCodeType= MethodCodeType. Native), SuppressUnmanag edCodeSecurity,
DllImport("", EntryPoint="", CallingConventi on=CallingConve ntion.StdCall,
SetLastError=tr ue)]
public static extern unsafe int modopt(CallConv Stdcall)
GetUserNameW(ch ar*, uint modopt(IsLong)* );
Greetings
Jochen

Feb 17 '07 #3

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

Similar topics

0
1112
by: Stephen Dybing [MSFT] | last post by:
Come join the SQL Server and CLR teams in a chat session focusing on CLR Integration in SQL Server 2005. You will be able to pose questions on all aspects of CLR integration, including when and how to take advantage of it, Visual Studio 2005 project support to write/debug/deploy managed code in SQL Server, reliability/scalability/performance/troubleshooting of managed code inside SQL Server and more. October 12, 2004 1:00 - 2:00 P.M....
7
2625
by: Gustavo L. Fabro | last post by:
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(dllexport). The compiler message is this: VCSelectLibraryForm.cpp ...\Forms\QiForm.h(48) : error C3395: 'TQiForm::GetDotNetMouseButton' :
2
4796
by: Peter Oliphant | last post by:
I've gotten my application to compile under '/clr'. I then tried '/clr pure' and it compiled immedately with no changes. What should I consider when deciding which of these two option to compile under? Are there advantages and disadvantages to one over the other? I also tried compiling it using the '/clr safe' option and got 6420 errors (no, that's not the error number, that's the number of errors). So don't think I'll go that route just...
5
1464
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 setting in that case.
1
1183
by: =?iso-8859-1?q?Horacio_Nu=F1ez_Hern=E1ndez?= | last post by:
Hi, I have been writing a wrapper with /clr:pure set, while I using the debug mode it was fine, when turned the mode to release it begins show me the same errors that when we try to use unmanaged functions whithout specify the input libs to the linker, thanks in advance, regards
10
7002
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam) {
13
3658
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 dependency without explicit p/invoke?
0
1591
by: gwe123 | last post by:
The problem is that in C++ windows Forms uses the /clr:pure in it compile. When one add the "ATL" namespace and includes it will compile but at runtime it die's bigtime. How does one retrieve information from the string table without using ATL?????
1
2253
by: neliomourato | last post by:
hi all. I was creating a program in c++ and have to use various libraries. the problem was that some libraries need the clr and one of them unfortunately need clr\pure. I want to know if is possible to use the both (clr and pure) in the same program? if yes, how i do it? i have to said that my level of programming is weak (basic).
0
9721
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
9601
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
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
10378
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,...
0
10115
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
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
5550
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
4332
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
3
3013
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.