473,325 Members | 2,608 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,325 software developers and data experts.

/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::GetLastWin32Error to check the last error code?
Feb 13 '07 #1
2 1743
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::GetLastWin32Error to check the last error code?
If you use DllImportAttribute, you can set "SetLastError" to true, this
will retrive the GetLastError value right after the call and you can use
the Marshal::GetLastWin32Error 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(szStr, &dwSize);
DWORD dw = GetLastError();
}
};
}

generates the following DllImport-Statement in VC2005:

[MethodImpl(MethodImplOptions.Unmanaged,
MethodCodeType=MethodCodeType.Native), SuppressUnmanagedCodeSecurity,
DllImport("", EntryPoint="",
CallingConvention=CallingConvention.StdCall, SetLastError=true)]
public static extern unsafe int modopt(CallConvStdcall)
GetUserNameW(char*, uint modopt(IsLong)*);
Greetings
Jochen
Feb 13 '07 #2
thank you...

"Jochen Kalmbach [MVP]" <no********************@holzma.dewrote in message
news:OJ**************@TK2MSFTNGP05.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::GetLastWin32Error to check the last error
code?

If you use DllImportAttribute, you can set "SetLastError" to true, this
will retrive the GetLastError value right after the call and you can use
the Marshal::GetLastWin32Error 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(szStr, &dwSize);
DWORD dw = GetLastError();
}
};
}

generates the following DllImport-Statement in VC2005:

[MethodImpl(MethodImplOptions.Unmanaged,
MethodCodeType=MethodCodeType.Native), SuppressUnmanagedCodeSecurity,
DllImport("", EntryPoint="", CallingConvention=CallingConvention.StdCall,
SetLastError=true)]
public static extern unsafe int modopt(CallConvStdcall)
GetUserNameW(char*, 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
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...
7
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...
2
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...
5
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...
1
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...
10
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...
13
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...
0
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.