473,799 Members | 3,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HOWTO call static managed function from unmanaged code.

A little more info.

I have a unmanaged C++ DLL, compiled without /CLR.
Inside a Managed C++ DLL, I have the following class:

MarshalWrapper. h
----
#ifdef _MANAGED
__nogc
#endif
class MarshalWrapper
{
public:
MarshalWrapper( );
~MarshalWrapper ();

static bool IsExceptionActi ve();
};

MarshalWrapper. cpp
----
MarshalWrapper: :MarshalWrapper ()
{
}

MarshalWrapper: :~MarshalWrappe r()
{
}

bool MarshalWrapper: :IsExceptionAct ive()
{
const unsigned long cnNoExceptionAc tive = 0xCCCCCCCC;
return Marshal::GetExc eptionCode() != cnNoExceptionAc tive;
}

Inside my Unmanaged C++ project, I add a reference to the Managed C++
project, and call MarshalWrapper: :IsExceptionAct ive().

I get the following error:
File1.obj : error LNK2019: unresolved external symbol "public: static
bool __cdecl MarshalWrapper: :IsExceptionAct ive(void)"
(?IsExceptionAc tive@MarshalWra pper@@SA_NXZ) referenced in function
"public: __thiscall File1::~File1(v oid)" (??1File1@@QAE@ XZ)

I tried changing the function declaration to be __cdecl, but this
caused other confusing problems.

All the examples I have are from calling managed code inside a managed
C++ project inside a #pragma unmanaged block, is it not possible to
make calls from a project not compiled with /CLR? If not, what are the
downsides to changing my unmanaged C++ project to /CLR? In particular,
are there any performance implications?

Thanks,
-ken
ra************* @gmail.com (Ken Durden) wrote in message news:<f3******* *************** ***@posting.goo gle.com>...
I'm trying to call

Marshall::GetEx ceptionCode() from Unmanaged C++.

Can I use gcroot to do this, or is there a simpler way?

-ken

Nov 17 '05 #1
0 1461

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

Similar topics

1
3220
by: sunil s via DotNetMonster.com | last post by:
Hi, I've got a native C++ app which calls a 3rd parth .NET DLL using the LoadLibrary/GetProcAddress functions. This works fine when the DLL is located in the app directory, but if I move it out to it's own directory, then I get a FileNotFoundException. I've tried manipulating the app.exe.config file's <codebase> parameter, but this doesn't seem to have any effect, possibly because the DLL does not have a strong name. The only thing...
24
7699
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my Dispose-Method and call the GC nothing happend!!! my Disposemethod has never been called!! so the GC dont call my Dispose-Method although I implemented IDisposable? what am i doing wrong?
2
1747
by: hykim | last post by:
I want to call a unmanaged dll's function returning some STRUCT's pointer. the next is definition of a STRUCT. ----------------------------------------------------------------------- typedef struct myStruct{ struct { UINT_PTR anything; UCHAR anything2; } myInnerStruct;
3
2108
by: Tony Liu | last post by:
Dear All: I create a very simple DLL by using EVC to test the problem. (The platform I am working for those program is WinCE.NET) ******************************************************* The header looks like: #ifdef TESTDLL_EXPORTS #define TESTDLL_API __declspec(dllexport)
2
9507
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how to do that? Thanks. Tsung-Yu
8
21252
by: ATS | last post by:
HOWTO Implement LoadLibrary\GetProcAdrress\FreeLibrary in C# Please help, I want to fully implement LoadLibrary\GetProcAdrress\FreeLibrary in C#, and be able to call functions that I use GetProcAddress on to pass info to non-.NET apps. I can not use the standard "interop" process, as the DLL's are created dynamically. I need this: ========================================
3
6508
by: ATS | last post by:
HOWTO Implement LoadLibrary, GetProcAdress, and FreeLibrary. Below is code that I want to be able to use simple LoadLibrary\GetProcAddress\FreeLibrary technqiues on. I've used the code that was initially placed on the .NET 247 forum as such: http://dotnet247.com/247reference//msgs/28/140461.aspx I have expanded it here to let one call any/all kinds of functions. The idea is that a "MASTER" Invoke function takes arrays that explain...
13
4151
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
3
3560
by: Sam Carleton | last post by:
I am writing Managed C++ code to call in to an Unmanaged C API. The reason for using Managed C++ over C# is that the Unmanaged C module is loaded via LoadLibrary(). DllImport cannot be used; functions pointers and GetProcAddress() is being used. The API function definition looks like this: int GetString( char* pszOutStr, int *nStrLen) It looks like the prototyping of the function pointer is straight
0
9688
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
9544
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,...
1
10238
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
10030
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
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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
5467
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...
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.