Solved

Handle for a non-mfc application

Posted on 1997-05-09
4
958 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Insert filename column as column a 18 76
Cannot debug web form sthrough Visual Studio 2013 2 83
SSRS troubles 4 68
Please explain purpose of GZIP 4 34
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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