0

Hi all,

Can any one please help me how to call an function from dll in vc++.

// test1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"
#include "conio.h"
#include "windef.h"


int _tmain(int argc, _TCHAR* argv[])
{
	
	HINSTANCE instcall=LoadLibrary(TEXT("c:\\test2.dll"));
	if(instcall==NULL)
	printf("Failed to load dll");
	FARPROC getproc=GetProcAddress(instcall,"funcall");
	if(getproc==NULL)
	printf("failed entry point");
	typedef int(__stdcall * picFunc)();
	picFunc funcall;
	funcall=picFunc(getproc);
	funcall();
getch();
//LPTSTR path=(LPTSTR)"c:\test2.dll";
	/*system("notepad.exe");
	DWORD threadId=dwThredId*/
/*typedef void *(_stdcall *creatfn)();
	creatfn myfunc=(creatfn) GetProcAddress(instcall,"call");
	void *objptr=myfunc();*/

	/*picFunc funcall;*/
//=picFunc(getproc);
	//funcall();
	///call=mycall(getproc);
}

I have this code in the main file
the dll file code is below

// test2.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "stdio.h"
#include "conio.h"

 void funcall()
{
	printf("hello");
}

When i execute i get this exception Unhandled exception at 0x00000000 in test1.exe: 0xC0000005: Access violation reading location 0x00000000.

Can any one please help me out in solving this problem. I am using Visual studio 2008 as compiler

Thank you

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by thines01
0

Yes i found the solution. The exception is because there was no .def file associated with dll. Creating def file with Library and exports overcomes this problem......

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.