473,770 Members | 7,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting handle to calling dll/exe

I'm using a library called fyba. This library reads and writes files in a
format called sosi. fyba uses the following code to determine if the
calling process has own methods to handle errors, messages, etc:

// If this parameter is NULL,
// GetModuleHandle returns a handle of the file used
// to create the calling process.
hInstExe = GetModuleHandle ( NULL );

if( hInstExe!=NULL )
LC_StartMessAdr = (void*)GetProcA ddress(hInstExe , "LC_StartMessDl l");

So, if LC_StartMessDll is found in the calling process, this function is
called. If it isn't found, a default function is called.
Now to my problem: my application consists of geo.exe and gcomm.dll.
gcomm.dll is the part that uses fyba, so I would like to be able to put the
callback functions in gcomm.dll, but since fyba uses the above method to
find the functions, they have to be in geo.exe. Is there a way to modify
the above code so that the methods will be found in gcomm.dll. More
precisely, I want to find the callback functions in the dll/exe that calls
fyba, not in the "top"-process (geo.exe). I hope I made myself clear.

Thanks in advance!

--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 7 '06 #1
2 2817
Daniel Lidström wrote:
So, if LC_StartMessDll is found in the calling process, this function is
called. If it isn't found, a default function is called.
Now to my problem: my application consists of geo.exe and gcomm.dll.
gcomm.dll is the part that uses fyba, so I would like to be able to put the
callback functions in gcomm.dll, but since fyba uses the above method to
find the functions, they have to be in geo.exe. Is there a way to modify
the above code so that the methods will be found in gcomm.dll. More
precisely, I want to find the callback functions in the dll/exe that calls
fyba, not in the "top"-process (geo.exe). I hope I made myself clear.


You can't do it. You must use a stub function in exe that in turn may
call anything else. Bad design, tough luck, sorry.

Actually, you may hack the code, so that the call to GetModuleHandle
gets redirected, but it is exotic and not recommended (and I never did it).
Mar 7 '06 #2
"Daniel Lidström" <so*****@micros oft.com> wrote in message
news:1u******** *************** *******@40tude. net...
I'm using a library called fyba. This library reads and writes files in a
format called sosi. fyba uses the following code to determine if the
calling process has own methods to handle errors, messages, etc:

// If this parameter is NULL,
// GetModuleHandle returns a handle of the file used
// to create the calling process.
hInstExe = GetModuleHandle ( NULL );

if( hInstExe!=NULL )
LC_StartMessAdr = (void*)GetProcA ddress(hInstExe , "LC_StartMessDl l");

So, if LC_StartMessDll is found in the calling process, this function is
called. If it isn't found, a default function is called.
Now to my problem: my application consists of geo.exe and gcomm.dll.
gcomm.dll is the part that uses fyba, so I would like to be able to put
the
callback functions in gcomm.dll, but since fyba uses the above method to
find the functions, they have to be in geo.exe. Is there a way to modify
the above code so that the methods will be found in gcomm.dll. More
precisely, I want to find the callback functions in the dll/exe that calls
fyba, not in the "top"-process (geo.exe). I hope I made myself clear.


You did.

There are two properties of Win32, both a little off the beaten track, that
_may_ make this possible.

First, it is not well-known but an executable can export functions. It's a
bit of a hack but I have used the trick once or twice in the last decade,
specifically when I have a DLL which can potentially be loaded into
different contexts. Inside the DLL, I look for an export with a given name
and if I find it, I make the assumption that the DLL is loaded into its
preferred context. It is a slightly brittle technique but that's a subject
for another day. In any event, perhaps you can export the function from your
executable.

Second, I know that what you really want to do is to export from your DLL.
Win32 supports export "forwarding " of DLLs. See this link

http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/ for a discussion. As the
article points out, NTDLL and KERNEL32 both have RtlHeapAlloc() functions.
Rather than implement it twice, or wrap one around the other, a little bit
of linker and loader voodoo is used to share the single implementation. So,
when KERNEL32 DLL is loaded, the loader just binds its RtlHeapAlloc() export
to the one in NTDLL.

Now, the $64,000 question is whether export forwarding works for functions
exported by executables. I don't know. If you try it, I'd surely like to
know, one way or the other.

May the force be with you. :-)

Regards,
Will
Mar 7 '06 #3

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

Similar topics

5
10124
by: Petec | last post by:
Is there a way to prevent a form from getting focus? Thanks! - Pete
1
15842
by: Matt | last post by:
Hi I am looking for a way in C# to use a IntPtr handle to a (possibly unmanaged) windows form to get the current position of the window on the desktop. I have tried using Form.FromHandle( handle ) but this does not work for non .NET windows. I am expecting to need to use SendMessage somewhere along the line, but cannot find the correct message to get the window position. Also, is there a way to perform simple operations on a window...
2
3054
by: Thomas Schoch | last post by:
I have a file with binary data and a dll where I have to pass a OLE_HANDLE which points to the data in the file. How do I read the data (i presume as binaryreader) and then pass the OLE_HANDLE to the function? Thomas
3
2037
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you propagating errors up the call stack? In the past, in my C++ code, I used to throw exceptions for ALL errors, exceptional or not. It seemed like a nice clean method for detecting, handling, and propagating errors. You can find multitudes of articles...
4
7795
by: planetthoughtful | last post by:
Hi All, I have a relatively simple web user control I've included in a page that simply presents 3 drop down lists and a submit button, that I use as a date picker (ie one list for day, one for month, one for year). I have the control registered on the page and it displays fine, but I haven't managed to work out how to get the value(s) back from the control on clicking the submit button (performs a postback). I want to use the date...
1
1403
by: Abhishek | last post by:
Hello All I am able to call the function exported by Exe from a dll file im getting the address of the function but whille calling that function im getting access violation Error as bellow my code Function Exported by EXE void __declspec(dllexport) ExeFn() {
6
2052
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in your business layer and/or data access layer? suppose in my data access layer, I provide try and catch, log the exception and re-throw it back to business layer, then in yoru business layer, what do you do? throw it back to the code behind or...
1
7469
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that represents the logged-on user. 2) Called ImpersonateLoggedOnUSer() to let the calling thread impersonate the security context of logged on user. 3) Used CreateEnvironmentBlock() to get lpEnv
33
11865
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon (NT_AUTHORITY\SYSTEM). I understand that when the service starts, no user may be logged in, but that's ok, as the app I am monitoring can only be run by a logged in user. Do I need to use WMI to get the user context of Explorer.exe or is there a...
0
9592
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
9425
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
10004
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
9870
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
6678
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();...
0
5313
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...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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.