AfxFreeLibrary is undeclared ?!?!

Hi all,
I have this problem:
I called a function from a dll I wrote. the function was exported correctly and also works great. both, the application and the dll are written in MFC. In the MSDN it is written that if you use multithreaded dlls you should use AfxFreeLibrary instead of FreeLibrary. And, when I tried to use FreeLibrary the program crashed. I, then tried to use AfxFreeLibrary but received a compiler error:
"error C2065: 'AfxFreeLibrary' : undeclared identifier"
I have all the proper include files but it still doesn't seem to work !!!
HELP
bareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Did you #define _AFXDLL ? Or is it specfied in your project settings?
0
mikeblasCommented:

AfxFreeLibrary() is delcared in AFXDLL_.H, which is referenced from AFXWIN.H.  It's only avaialable if you're building with the _AFXDLL symbol.

Maybe you're not building _AFXDLL.  Or, maybe you've screwed-up some other construct, like an extern "C", or a namespace.

..B ekiM
0
chensuCommented:
To be clear, _AFXDLL is defined when you build an MFC extension DLL.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

mikeblasCommented:
chensu> To be clear, _AFXDLL is defined when you
 chensu> build an MFC extension DLL.  

That's not really clear.  Your phrasing implies that it's defined for you. In fact, you need to define it. Normally, that's done on the CL command line with the /D option (that is, in the "Preprocessor definitions" edit on the "General" category in the "C/C++" tab of your project settings).

Yes, you need to define this symbol when you're building an extension DLL.  But there are other situations when you'll define it--when building an executable that uses MFC in a shared DLL, for example.

..B ekiM
0
inprasCommented:
Hi bare
Have U defined VC_EXTRALEAN or WIN32_LEAN_AND_MEAN, or WIN32_EXTRA_LEAN
Then Make sure you are including any necessary header files. The VC help says that Defining these symbols excludes some functionality (certain header files are excluded) from windows.h and afxv_w32.h (for MFC applications) to speed compiles. Search windows.h and afxv_w32.h for these symbols for the most up-to-date description of what is excluded.
Regards
0
cdesignerCommented:
You can't use FreeLibrary ?
try
0
bareAuthor Commented:
Thanks to all of you for the comments.
Now, for my comment:
Well, I've been using WIN32_LEAN_AND_MEAN and VC_EXTRALEAN etc. It still doesn't recognise the function with or withou these macros. For those of u who didn't understand, I have this problem in the executable and not a dll. I, too, read that afxdll_.h is excluded when compiling if it is not DLL project, but what I'm actually asking is: if I'm told to use AfxFreeLibrary instead FreeLibrary (as written in the MSDN), then why doesn't my project recognize this function. It could be that I screwed something in the project itself, but can't find it myself !!! How can I make it to work? FreeLibrary causes the program to crash (just like they promised ....;-)
bare
0
mikeblasCommented:
> It still doesn't recognise the function with or withou these macros.

Those macros don't affect MFC.  They affect the system headers--that is, Windows and OLE APIs, only.

 > then why doesn't my project recognize this function.
 > It could be that I screwed something in the project itself,
 > but can't find it myself !!!

We can't find it for you unless you answer our questions. Is _AFXDLL defined for your build, or not?

..B ekiM
0
bareAuthor Commented:
.B ekiM,
With the _AFXDLL defined the situation gets even worse and that is very understandable, because, if you read what I've wrote above you could see that I'm writing an executable and not a dll. When defining the _AFXDLL it gives a #error message !
I don't think this is the problem ...
yet it could be something in the project ...

bare.
0
bareAuthor Commented:
.B ekiM,
With the _AFXDLL defined the situation gets even worse and that is very understandable, because, if you read what I've wrote above you could see that I'm writing an executable and not a dll. When defining the _AFXDLL it gives a #error message !
I don't think this is the problem ...
yet it could be something in the project ...

bare.
0
mikeblasCommented:
> defining the _AFXDLL it gives a #error message !

What #error message do you get, exactly? (It's pretty hard to help you when information about the symptoms you're having is so hard to come by.)

 > if you read what I've wrote above you could
 > see that I'm writing an executable and not a dll.

Actually, I read what you wrote. I see that you're writing _both_ a DLL and an EXE, but you're having problems getting the executable to build.

What I _don't_ see is any hint that being so abrasive will get you any help.

..B ekiM
0
Oliver_DornaufCommented:
Use defines for to build the ExeE :
WIN32, _WINDOWS, _AFXDLL

Use defines for DLL:
WIN32, _WINDOWS, _WINDLL, _AFXDLL,_AFXEXT

you also have to define _MBCS or _UNICODE

this works fine with VC 6

0
mikeblasCommented:
> Use defines for DLL:

Actually, that depends on what kind of DLL you're building.

..B ekiM
0
bareAuthor Commented:
The reason I rejected the answer is that I've already been proposed to add _AFXDLL to the defines. when I do so I get a #error (as described above). After looking at that header file I so that it also requires to define _DLL. I defined it and it suddenly recognized the AfxFreeLibrary function. So the answer is to _AFXDLL *and* _DLL to the definitions of the project ...

10x all for you attention ........

bare
0
mikeblasCommented:
> when I do so I get a #error (as described above).

Huh?  You didn't describe a darned thing!  We still don't know which error message you received.

 > . So the answer is to _AFXDLL [sic] *and* _DLL to the
 > definitions of the project ...

Great! I'm glad you solved your problem. In the future, you should remember that being more forthcoming about the details will get you better help faster.

..B ekiM
0
cyberfrankCommented:
Hi!

To be sure. Are You use AfxLoadLibrary instead of LoadLibrary too? Because teher will be problems if you don't use.
BTW:
In MSDN, there is two examples which uses AfxLoadLibrary/AfxFreeLibrary. Check those examples and compare it with yours, to be sure that the settings are same:
mk:@MSITStore:d:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98OCT\1033

and for example, in release mode following setting are set for the compiler:
WIN32,NDEBUG,_WINDOWS,_AFXDLL,_MBCS

CF
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikeblasCommented:
Trying to poach, cyberfrank?

..B ekiM
0
cyberfrankCommented:
Hi!
...B ekiM what's your problem?

CF
0
bareAuthor Commented:
The answer is good, and in fact, i already solved it that way ....
10x 2 all of u guys ........

btw, there's also a need 2 add _DLL in order 4 all u adviced 2 work ....

bare
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.