473,795 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ManagedC++, Garabage collection and function pointer

I have some managed C++ interacting with native DLL,
for good integration I'm setting up some function pointer in the native DLL,
passing some function pointer from the managed world.
=============== ==
typedef void __cdecl NSLogHandler(Oi d exception);
static void __cdecl ObjectiveNSLogH andler(Oid ns_str)
{
NSString^ str = dynamic_cast<NS String^>( ObjcRuntime::Ge tId(ns_str) );
Console::WriteL ine("GNUstep.NE T: "+str);
}

void ObjcRuntime::Se tupNSLogHandler ()
{
NSLogHandler** p_nslog_h = (NSLogHandler** ) GetProcAddress( _hLibGSBase,
"_NSLog_printf_ handler");
if( !p_nslog_h )
throw gcnew ObjectiveCExcep tion("Cannot set NSLog Handler");
*p_nslog_h = &ObjectiveNSLog Handler;
}
=============== ==

I wonder if it's allright or if the code (hence its address) could be moved
too?
what could I do in this case?

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
Mar 16 '06 #1
1 1227
"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
I have some managed C++ interacting with native DLL,
for good integration I'm setting up some function pointer in the native
DLL, passing some function pointer from the managed world.
=============== ==
typedef void __cdecl NSLogHandler(Oi d exception);
static void __cdecl ObjectiveNSLogH andler(Oid ns_str)
{
NSString^ str = dynamic_cast<NS String^>( ObjcRuntime::Ge tId(ns_str) );
Console::WriteL ine("GNUstep.NE T: "+str);
}

void ObjcRuntime::Se tupNSLogHandler ()
{
NSLogHandler** p_nslog_h = (NSLogHandler** ) GetProcAddress( _hLibGSBase,
"_NSLog_printf_ handler");
if( !p_nslog_h )
throw gcnew ObjectiveCExcep tion("Cannot set NSLog Handler");
*p_nslog_h = &ObjectiveNSLog Handler;
}
=============== ==

I wonder if it's allright or if the code (hence its address) could be
moved too?
what could I do in this case?


I am not sure I understood your question totally, but my gut feeling is,
your approach will not be successful. GetProcAddress gives you a function
pointer. You cast a function pointer into a function pointer pointer.

From your explanations, I assume you
a) have a managed DLL that calls exported methods of a native DLL.
b) want to call one of the exported functions of the DLL which expects a
native function pointer as an argument
c) want to pass a pointer to managed function with this method call

If my assumption is right, then you should know that managed functions can
have native calling conventions and that you can get the address of a
managed function with a native calling convention. This address is a native
function pointer that you use like any other native function pointer. So you
can pass it to your exported function of the native DLL. Under the hood,
C++/CLI creates so called vtfixups in your assembly. This is metadata that
is used by the runtime to create an unmanged / managed thunk, which is
(roughly spoken) the function that the native client actually calls. It is
the job of this thunk to call the managed function.
Mar 16 '06 #2

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

Similar topics

8
2217
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in the process), I looked up the STL code. Erase certainly does not delete the memory associated with the element. However, it appears that the destructor on the element is invoked. I wonder why it has to be this way. In my opinion, this renders...
0
1079
by: KK | last post by:
Hi .net gurus, I am new to .net.I'm trying to use an unmanaged class in my ManagedC++ project.The unmanaged class is using CString as it's member variable.When I tried to run the application I'm getting access violation on CString implementation.(GetData() method of CString class causing violation because internal data pointer is nil).Can anybody help me in figuring out why I'm getting such errors? Thanks in advance
2
2517
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
11
1964
by: Lloyd Dupont | last post by:
(not I use 2.0, so new return a "normal" pointer and gcnew return a managed one, my question below regarding new concern plain standart C++ allocator) - if I use the default new operator, are all the instance variable initialize to NULL / 0 ? - if there is not enough memory what happend with new ? does it return NULL or throw an exception? - if new throw a native C++ exception what happen in Managed C++ ?! - if there is an exception in...
2
1826
by: Victor Nazarov | last post by:
I've tried to implement some garbage collection library for see. Here is an example of it's usage. Do you think that it is usefull at all and deserve development? #include <stddef.h> #include <stdlib.h> #include <stdio.h> #include "virlib.h" void fclose_p (void *p);
4
1699
by: R. MacDonald | last post by:
Hello, all, I have a .NET application (VB) that passes the address of a delegate to unmanaged code in a DLL. The unmanaged code then uses the delegate as a call-back. This seems to work fine, but now I am worried about garbage collection. I am concerned that the location of the delegate might be altered as a result of other (unused) objects being garbage collected. This would probably cause undesirable results when the unmanaged DLL...
28
3189
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will this work be library based or language based and will it be based on that of managed C++? Then of course there are the finer technical questions raised (especially due to pointer abuse). Is a GC for C++ just a pipe dream or is there a lot of work...
20
7106
by: silverburgh.meryl | last post by:
In my code, I have an array of char* pointer which is populated statically: void function1() { char *ppsz_argv2 = { "abc" , "def", "dummy"}; //... }
5
4665
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
0
9673
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
9522
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
10217
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
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,...
1
7544
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
6784
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();...
1
4114
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
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
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.