Click here to Skip to main content
15,899,679 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Simple app to call dll Pin
ThatsAlok6-Nov-04 17:49
ThatsAlok6-Nov-04 17:49 
GeneralRe: Simple app to call dll Pin
mjeb11117-Nov-04 10:59
mjeb11117-Nov-04 10:59 
GeneralRe: Simple app to call dll Pin
ThatsAlok7-Nov-04 18:12
ThatsAlok7-Nov-04 18:12 
GeneralRe: Simple app to call dll Pin
mjeb11117-Nov-04 18:33
mjeb11117-Nov-04 18:33 
GeneralRe: Simple app to call dll Pin
ThatsAlok7-Nov-04 21:58
ThatsAlok7-Nov-04 21:58 
GeneralRe: Simple app to call dll Pin
ThatsAlok7-Nov-04 21:58
ThatsAlok7-Nov-04 21:58 
GeneralRe: Simple app to call dll Pin
mjeb11117-Nov-04 22:32
mjeb11117-Nov-04 22:32 
GeneralRe: Simple app to call dll Pin
jan larsen9-Nov-04 0:48
jan larsen9-Nov-04 0:48 
Here you are:

///////////////////////////////////////////////////////////////////////////
#include <windows.h>
///////////////////////////////////////////////////////////////////////////
// We'll define the file pointers as types, it's a great help for us and
// the compiler.
typedef BOOL (__stdcall * MYGETOPENFILENAME)(HWND ghWnd, LPTSTR szName, 
                                               LPTSTR szInitDir);
///////////////////////////////////////////////////////////////////////////
// This is the actual function pointer that we have to set before use.
MYGETOPENFILENAME MyGetOpenFileName;
///////////////////////////////////////////////////////////////////////////
// A function to show a windows error message.
static void ShowLastError()
{
	LPVOID lpMsgBuf;
	if (!FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER | 
		FORMAT_MESSAGE_FROM_SYSTEM | 
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		GetLastError(),
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		0,
		NULL ))
	{
	   // Handle the error.
	   return;
	}

	// Process any inserts in lpMsgBuf.
	// ...

	// Display the string.
	MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONERROR );

	// Free the buffer.
	LocalFree( lpMsgBuf );
}
///////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                     LPSTR lpCmdLine, int nShowCmd)
{
	// The filename buffer.
	TCHAR		filename[MAX_PATH];

	// Getting a handle to the dll.
	HMODULE		hDll = LoadLibrary(TEXT("ipong.dll"));	

	// Testing if we got a valid handle.
	if (NULL != hDll)
	{
		// Then we initializes our function pointer.
		MyGetOpenFileName = (MYGETOPENFILENAME) GetProcAddress(hDll, TEXT("MyGetOpenFileName"));

		// Testing if we found the function.
		if (NULL != MyGetOpenFileName)
		{
			lstrcpy(filename, TEXT("test.txt"));

			// Let's try it then...
			if(MyGetOpenFileName(NULL, filename, TEXT("C:\\")))
			{
				MessageBox(NULL, filename, TEXT("Testing"), MB_OK);
			}
		}
		else
		{
			ShowLastError();
		}


		// Cleaning up.
		FreeLibrary(hDll);
	}
	else
	{
		ShowLastError();
	}

	return 0;
}
///////////////////////////////////////////////////////////////////////////


"After all it's just text at the end of the day. - Colin Davies

"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
GeneralRe: Simple app to call dll Pin
mjeb11119-Nov-04 6:52
mjeb11119-Nov-04 6:52 
GeneralFont height in pixel Pin
Vancouver6-Nov-04 11:43
Vancouver6-Nov-04 11:43 
GeneralRe: Font height in pixel Pin
Michael Dunn6-Nov-04 15:00
sitebuilderMichael Dunn6-Nov-04 15:00 
GeneralRe: Font height in pixel Pin
Vancouver6-Nov-04 20:53
Vancouver6-Nov-04 20:53 
QuestionHow to print out a character Pin
Cuu6-Nov-04 10:38
Cuu6-Nov-04 10:38 
AnswerRe: How to print out a character Pin
faroqtam6-Nov-04 12:36
faroqtam6-Nov-04 12:36 
GeneralRe: How to print out a character Pin
Cuu8-Nov-04 15:15
Cuu8-Nov-04 15:15 
AnswerRe: How to print out a character Pin
ThatsAlok6-Nov-04 17:28
ThatsAlok6-Nov-04 17:28 
GeneralRe: How to print out a character Pin
Cuu8-Nov-04 15:16
Cuu8-Nov-04 15:16 
GeneralRe: How to print out a character Pin
ThatsAlok8-Nov-04 18:24
ThatsAlok8-Nov-04 18:24 
AnswerRe: How to print out a character Pin
David Crow8-Nov-04 5:24
David Crow8-Nov-04 5:24 
Generali need help plzzzz my first time to use classes Pin
Member 13942596-Nov-04 9:19
Member 13942596-Nov-04 9:19 
GeneralRe: i need help plzzzz my first time to use classes Pin
Christian Graus6-Nov-04 9:27
protectorChristian Graus6-Nov-04 9:27 
GeneralRe: i need help plzzzz my first time to use classes Pin
Member 13942596-Nov-04 10:39
Member 13942596-Nov-04 10:39 
GeneralRe: i need help plzzzz my first time to use classes Pin
6-Nov-04 10:44
suss6-Nov-04 10:44 
Generalpopular Java forums Pin
includeh106-Nov-04 8:08
includeh106-Nov-04 8:08 
GeneralWindow Restore Pin
Leyu6-Nov-04 8:02
Leyu6-Nov-04 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.