简体   繁体   中英

Difference between C# and VB.NET console session

Ok, so I have this code written in C++ that call the function SetThreadDesktop . I call this function from a dll when running as System user on Windows XP.

When called from a C# console application, the function succeeds, but when called from a VB.NET console application, it doesn't. With GetLastError , I saw that the error message was this:

SetThreadDesktop failed with error 170: The requested resource is in use (translated from french)

How does it come that it works for a C# console app and not for a VB.NET one? Btw, it doesn't work for a winform app neither. Can any .NET master explain this to me? Is it a compiler option that I have to change?

Thanks

Try adding a <MTAThread> attribute on your (VB) Main method as explained here .

That's really the only thing that differs between C# and VB Console projects by default.

Shouldn't you declare the extern function as public shared ?

<DllImport("AltCtrlDelCpp.dll")> _
Public Shared Function SimulateAltControlDel() As Boolean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM