473,385 Members | 1,829 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,385 software developers and data experts.

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(Oid exception);
static void __cdecl ObjectiveNSLogHandler(Oid ns_str)
{
NSString^ str = dynamic_cast<NSString^>( ObjcRuntime::GetId(ns_str) );
Console::WriteLine("GNUstep.NET: "+str);
}

void ObjcRuntime::SetupNSLogHandler()
{
NSLogHandler** p_nslog_h = (NSLogHandler**) GetProcAddress(_hLibGSBase,
"_NSLog_printf_handler");
if( !p_nslog_h )
throw gcnew ObjectiveCException("Cannot set NSLog Handler");
*p_nslog_h = &ObjectiveNSLogHandler;
}
=================

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 1210
"Lloyd Dupont" <net.galador@ld> wrote in message
news:%2***************@TK2MSFTNGP14.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(Oid exception);
static void __cdecl ObjectiveNSLogHandler(Oid ns_str)
{
NSString^ str = dynamic_cast<NSString^>( ObjcRuntime::GetId(ns_str) );
Console::WriteLine("GNUstep.NET: "+str);
}

void ObjcRuntime::SetupNSLogHandler()
{
NSLogHandler** p_nslog_h = (NSLogHandler**) GetProcAddress(_hLibGSBase,
"_NSLog_printf_handler");
if( !p_nslog_h )
throw gcnew ObjectiveCException("Cannot set NSLog Handler");
*p_nslog_h = &ObjectiveNSLogHandler;
}
=================

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
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...
0
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...
2
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...
11
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...
2
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...
4
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...
28
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...
20
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...

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.