Solved

Handle for a non-mfc application

Posted on 1997-05-09
4
948 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No, just a normal .lib. The GetModuleHandle function works just fine and you saved me some time stuffing around. Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now