Solved

Handle for a non-mfc application

Posted on 1997-05-09
4
966 Views
Last Modified: 2013-12-04
Simple - I have a non-mfc windows (95/NT) application that is portable and cannot contain windows-specific code (has 3rd-party GUI/system libs). However in a library I have built I have windows stuff - such as TAPI function calls - and I need to get the application handle. I want to use AfxGetApp, AfxGetInstanceHandle, etc. Everything links OK, but the Afx... functions cause an ASSERT. Do I need to manually initialise some Afx thingy inside my lib?

Alternatively, there's probably a better way to get the apps handle ?

(Forgive me, I've been using mfc too long and my brain has gone mushy.)

Thanx in advance
0
Comment
Question by:TimeLord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1397219
Using AfxGetApp, AfxGetInstanceHandle, etc in a non-mfc application is not good because you have to initialize many variables yourself. You can check MFC source code. The better way is to just get the instance handle in WinMain(). Record the instance handle and transfer it to your lib.
0
 

Author Comment

by:TimeLord
ID: 1397220
Ah, no-can-do. I am sort-of familiar with the WinMain technique; however, that is windows-specific (and anyway the automatic code generator from the 3rd-party GUI tool generates a portable 'main', not a WinMain).

And of course I can't put WinMain in my library... there must be another way?? I mean, the 3rd-party libs must have windows handles for internal use when the code is being compiled for a PC...
0
 
LVL 3

Accepted Solution

by:
Melange earned 100 total points
ID: 1397221
Is your windows library a DLL? You'll need to make sure that is a self-contained MFC DLL and not an extension DLL. Then the DLL will have a self-contained CWinApp from which you can use AfxGetApp, AfxGetInstanceHandle, etc. Failing that you can simple call "GetModuleHandle" with NULL as the parameter to retrieve the applications HMODULE handle (equivalent to HINSTANCE).
0
 

Author Comment

by:TimeLord
ID: 1397222
No, just a normal .lib. The GetModuleHandle function works just fine and you saved me some time stuffing around. Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question