Click here to Skip to main content
15,906,463 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralThanks :-) Pin
baerten7-May-08 22:42
baerten7-May-08 22:42 
QuestionOpening existing file without checking the file extension Pin
FPeeters7-May-08 22:23
FPeeters7-May-08 22:23 
AnswerRe: Opening existing file without checking the file extension Pin
Christian Graus7-May-08 22:24
protectorChristian Graus7-May-08 22:24 
GeneralRe: Opening existing file without checking the file extension Pin
FPeeters7-May-08 22:41
FPeeters7-May-08 22:41 
GeneralRe: Opening existing file without checking the file extension Pin
Iain Clarke, Warrior Programmer8-May-08 4:36
Iain Clarke, Warrior Programmer8-May-08 4:36 
AnswerRe: Opening existing file without checking the file extension Pin
Michael Schubert8-May-08 0:00
Michael Schubert8-May-08 0:00 
AnswerRe: Opening existing file without checking the file extension Pin
David Crow8-May-08 4:11
David Crow8-May-08 4:11 
Questionerror loading functions from dll.... Pin
alex7867-May-08 21:55
alex7867-May-08 21:55 
i am new to creating dll and using function from them by dynamic loading....


see i made a program....and defined a function test() in that....i tried to load that...but not getting output....my files are..

----------------------------------------------------------------------------
//library header file key.h

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


DLLIMPORT void test( );

#endif /* _DLL_H_*/
--------------------------------------------------------------

//dllmain.cpp file
-----------------------------------------------------------------
/* Replace "dll.h" with the name of your header */
#include <windows.h>
#include "key.h"

DLLIMPORT void test( )
{
MessageBox( HWND_DESKTOP,"TEST DONE","hi",MB_OK | MB_ICONINFORMATION);
}



BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpReserved ) // reserved
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
MessageBox( HWND_DESKTOP,"DLL_PROCESS_ATTACH","info",MB_OK | MB_ICONINFORMATION);
break;

case DLL_PROCESS_DETACH:
MessageBox( HWND_DESKTOP,"DLL_PROCESS_DETACH","info",MB_OK | MB_ICONINFORMATION);
break;

case DLL_THREAD_ATTACH:
MessageBox( HWND_DESKTOP,"DLL_THREAD_ATTACH","info",MB_OK | MB_ICONINFORMATION);
break;

case DLL_THREAD_DETACH:
MessageBox( HWND_DESKTOP,"DLL_THREAD_DETACH","info",MB_OK | MB_ICONINFORMATION);
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
-----------------------------------------------------------------------



/my main.cpp using above library by dynamic loading....
#include <windows.h>
#include <stdio.h>
#include <winuser.h>
#include <windowsx.h>
#include <time.h>

HWND hwndMain;
HINSTANCE hinstDLL;

typedef VOID (*MYPROC)(LPTSTR); ///don't understand this....i think this should be.... typedef VOID (*MYPROC)( )..
MYPROC test;

/* Make the class name into a global variable */
char szClassName[ ] = "svc";


/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);



int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwndMain = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"svchost", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
350, /* The programs width */
150, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwndMain, 1);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

switch ( message )
{
case WM_CREATE:


hinstDLL = LoadLibrary("keylib.dll");
if( hinstDLL == NULL )
{
MessageBox(hwndMain,"Error Loading DLL","done",MB_OK | MB_ICONINFORMATION);
}
else
{
MessageBox(hwndMain,"Loaded","done",MB_OK | MB_ICONINFORMATION);
}

test = (MYPROC) GetProcAddress( hinstDLL, "test" );

if( test == NULL )
{
MessageBox(hwndMain,"TEST LOAD FAILED","error",MB_OK | MB_ICONINFORMATION);
}
else
{
MessageBox(hwndMain,"TEST LOAD FAILED","error",MB_OK | MB_ICONINFORMATION);
(test);///don't know why this is used......plz explain someone...i think it should be test();....
}
break;

case WM_DESTROY:

PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
-----------------------------------------------------------------
when im compiling the dll n using in my main.h...then it shows a message window with "LOADED" which means library is loaded...but it does not show any message window defined in the library entry function (DllMain's switch statement).....n it shows "TEST LOAD FAILED"...don't know why..please help me..i read an article on microsofts site for using dll n thats what im doing....link is
http://support.microsoft.com/kb/815065[^]
please help someone...
i also tried using
typedef void (*MYPROC)( );//like function pointer..n then using
MYPROC test;
its giving same outputs...first point that is making me mad is why the hell its not executing any of the MessageBOX( function in DllMain function...which is entry point...thanx...
QuestionRe: error loading functions from dll.... Pin
CPallini7-May-08 22:33
mveCPallini7-May-08 22:33 
AnswerRe: error loading functions from dll.... Pin
Nitheesh George7-May-08 23:09
Nitheesh George7-May-08 23:09 
AnswerRe: error loading functions from dll.... Pin
Nitheesh George7-May-08 23:11
Nitheesh George7-May-08 23:11 
Question0xC0000005: Access Violation Pin
Bernaad7-May-08 20:33
Bernaad7-May-08 20:33 
AnswerRe: 0xC0000005: Access Violation Pin
Cedric Moonen7-May-08 20:40
Cedric Moonen7-May-08 20:40 
AnswerRe: 0xC0000005: Access Violation Pin
dehseth7-May-08 20:55
dehseth7-May-08 20:55 
AnswerRe: 0xC0000005: Access Violation Pin
Jonathan [Darka]7-May-08 21:04
professionalJonathan [Darka]7-May-08 21:04 
AnswerRe: 0xC0000005: Access Violation Pin
Hamid_RT7-May-08 21:16
Hamid_RT7-May-08 21:16 
AnswerRe: 0xC0000005: Access Violation Pin
CPallini7-May-08 21:33
mveCPallini7-May-08 21:33 
GeneralRe: 0xC0000005: Access Violation Pin
Bernaad8-May-08 0:14
Bernaad8-May-08 0:14 
Questionprinting Pin
bijumon Mathew7-May-08 20:28
bijumon Mathew7-May-08 20:28 
AnswerRe: printing Pin
Hamid_RT7-May-08 20:45
Hamid_RT7-May-08 20:45 
QuestionURLDownloadToCacheFile() or URLDownloadToFile() question Pin
monsieur_jj7-May-08 20:27
monsieur_jj7-May-08 20:27 
AnswerRe: URLDownloadToCacheFile() or URLDownloadToFile() question Pin
Hamid_RT7-May-08 20:48
Hamid_RT7-May-08 20:48 
GeneralRe: URLDownloadToCacheFile() or URLDownloadToFile() question Pin
monsieur_jj7-May-08 20:50
monsieur_jj7-May-08 20:50 
GeneralRe: URLDownloadToCacheFile() or URLDownloadToFile() question Pin
David Crow8-May-08 4:27
David Crow8-May-08 4:27 
AnswerRe: URLDownloadToCacheFile() or URLDownloadToFile() question Pin
Garth J Lancaster7-May-08 23:21
professionalGarth J Lancaster7-May-08 23:21 

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.