Hello there! I'm currently doing some VC++ programming. I'm using MFC programming and DLL which is explicitly linked. I have placed my initialization and the usage of GetProcAdress inside my "buttonClicked" function. When a button is clicked, the function in the DLL should be called.

void CSample::buttonClicked(){
	if(hLib){
		pSampleFunc = (SampleFunc)GetProcAddress(hLib, "Sample");
		
		if(pSampleFunc ){
			
			pSampleFunc (iVar, cVar);
		}

		FreeLibrary(hLib);
	}else{
		MessageBox("Library Failed!");
	}

        //DO SOME STUFF HERE
       ......

}

The first execution of the button is successful but if I pressed it the second time, it does nothing. What do you think is the problem? Please advise. Thank you. :)

Recommended Answers

All 2 Replies

Since you are calling FreeLibrary(hLib); , maybe you've forgotten to (re)LoadLibrary(...)?

I have solved the problem. I transferred FreeLibrary function in my exit function and transferred my initializationof pSampleFunc to OnInit function. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.