|
sujandasmahapatra wrote: My application is appearing and disappearing from the screen.
when?
have you tried stepping through it in the debugger?
|
|
|
|
|
nothing is happening with debugger..its dll.....
appearing and disappearing....please give me some suggestion how can i launch the dll application from console client. Thanks a lot for comments. Thanks Sujan
|
|
|
|
|
|
That's hardly surprising since it's a console app trying to run a Windows DLL. you also seem to have a discrepancy between the definition of your runAppli() function and its implementation.
|
|
|
|
|
I am able to reduce the code to this much but still its crashing...
/////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"runAppli");
/*
Define the Function in the DLL for reuse. This is just prototyping the dll's function.
A mock of it. Use "stdcall" for maximum compatibility.
*/
typedef BOOL (* pICFUNC)(HINSTANCE, LPCSTR);
pICFUNC MyFunction=NULL;
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = MyFunction(HMODULE (hGetProcIDDLL), "runAppli");
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////
__declspec(dllexport) void runAppli()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
}
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
First point: please use <pre> tags around your code so that it is more readable.
Second point:
pICFUNC MyFunction=NULL;
BOOL intMyReturnVal = MyFunction(HMODULE (hGetProcIDDLL), "runAppli");
how do you expect a call to a NULL address not to crash?
|
|
|
|
|
Now I am writing like this.
int main(int argc, char **argv)
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
typedef BOOL (* pICFUNC)(HINSTANCE, LPCSTR);
pICFUNC lpfnGetProcessID = (pICFUNC)GetProcAddress((HMODULE) hGetProcIDDLL,"runAppli");
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = lpfnGetProcessID((HMODULE) hGetProcIDDLL, "runAppli");
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)
{
// Only needed if resources are accessed
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
::ShowWindow(hwnd, SW_SHOW);
UNREFERENCED_PARAMETER(lpAppName);
return true;
}
Somebody suggested this piece of code. But nothing is appearing with this. My mainwindow of the dll application is not coming.
Can u tell me whats wrong still in this. Thanks a lot for your help. Sujan
|
|
|
|
|
LoadLibrary[^] returns a HMODULE , not HINSTANCE . Alter the DLL loading to look like this:
HMODULE hDll = LoadLibrary(_T("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
Secondly, lose the cast like this (since you're now using the correct type above):
typedef BOOL (*PFUNC)(HINSTANCE, LPCSTR);
PFUNC pProc = (PFUNC)GetProcAddress(hDll, "runAppli");
Note also that I've added a _T (same as TEXT ) which you left out.
Now a guess at the cause of your problems: GetProcAddress[^] is failing because you're using the wrong function name by ignoring name mangling[^]. Change the DLL like this:
extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)
Steve
modified 23-Oct-11 6:01am.
|
|
|
|
|
With this even its not happening stephen...
_T is not compiling so I have put only the text. its compiling
Now the code looks like this..
int main(int argc, char **argv)
{
/* get handle to dll */
HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
typedef BOOL (* ICFUNC)(HINSTANCE, LPCSTR);
ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli");
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = lpfnGetProcessID(hDll, "runAppli");
/* Release the Dll */
FreeLibrary(hDll);
return 0;
}
extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)
{
// Only needed if resources are accessed
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
::ShowWindow(hwnd, SW_SHOW);
UNREFERENCED_PARAMETER(lpAppName);
return true;
}
|
|
|
|
|
sujandasmahapatra wrote: With this even its not happening stephen...
_T is not compiling so I have put only the text. its compiling
Yeah, I was wrong on that point. You don't use _T on GetProcAddress . I have modified my post to reflect this.
So it works now?
Steve
|
|
|
|
|
Now the code is looking like this ....But still application is not launching.
int main(int argc, char **argv)
{
/* get handle to dll */
HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
typedef BOOL (* ICFUNC)(HINSTANCE, LPCSTR);
ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli");
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = lpfnGetProcessID(hDll, "runAppli");
/* Release the Dll */
FreeLibrary(hDll);
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)
{
// Only needed if resources are accessed
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
::ShowWindow(hwnd, SW_SHOW);
UNREFERENCED_PARAMETER(lpAppName);
return true;
}
|
|
|
|
|
Why are you passing a HMODULE when a HWND is expected?
sujandasmahapatra wrote: BOOL intMyReturnVal = lpfnGetProcessID(hDll, "runAppli");
sujandasmahapatra wrote: extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)
Steve
|
|
|
|
|
With this even its not launching the application. simply returning. dll application is not launching. some more things are missing it seems. Please let me know if you're able to figure it out. Thanks for your help sujan
|
|
|
|
|
typedef BOOL (* ICFUNC)(HINSTANCE, LPCSTR);
ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli");
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = lpfnGetProcessID(hDll, "runAppli");
lpfnGetProcessID expects a HMODULE right...? Is it wrong. ??
|
|
|
|
|
How can I get the handle from the client console and pass it to the lpfnGetProcessID .... to runAppli....With the code below I am getting run-time error. that hwnd being used without being intialized.. Please tell me how can I initialize hwnd. Thanks Sujan
int main(int argc, char **argv)
{
HWND hwnd;
/* get handle to dll */
HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
typedef BOOL (* ICFUNC)(HWND, LPCSTR);
ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli");
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = lpfnGetProcessID(hwnd, "runAppli");
/* Release the Dll */
FreeLibrary(hDll);
return 0;
}
|
|
|
|
|
You're not explaining yourself very clearly but it sounds like you might be after the GetConsoleWindow function.
Steve
|
|
|
|
|
extern "C" BOOL __declspec(dllexport) runAppli(HWND hwnd, LPCSTR lpAppName)
{
// Only needed if resources are accessed
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
::ShowWindow(hwnd, SW_SHOW);
UNREFERENCED_PARAMETER(lpAppName);
return true;
}
So I need to pass hwnd to this function right..? Is it necessary to launch my dll application. I just want to launch the application.
|
|
|
|
|
Why don't you explain exactly what you are trying to do?
Steve
|
|
|
|
|
I want to launch my dll application from win32 client exe.......Can u help me whats need be done Thanks for your help.
|
|
|
|
|
I want to show the mainwindow of the dll application from win32 client. I am able to load the dll but I am confused what need to be done after that to show the mainwindow. Please help Stephen. Thanks Sujan
|
|
|
|
|
Firstly note that a dll and the code that loads it are in the same application; I'm starting to get the impression that you may not be aware of this. Also, maybe you should use static linking.
Steve
|
|
|
|
|
I have made some changes in the code let me know whats wrong in this my application is not launching.
int main(int argc, char **argv)
{
HWND hWnd=NULL;
/* get handle to dll */
HMODULE hDll = LoadLibrary(TEXT("C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll"));
typedef BOOL (* ICFUNC)(LPCSTR);
ICFUNC lpfnGetProcessID = (ICFUNC)GetProcAddress(hDll, "runAppli");
///* The actual call to the function contained in the dll */
BOOL intMyReturnVal = lpfnGetProcessID("runAppli");
/* Release the Dll */
FreeLibrary(hDll);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
extern "C" BOOL __declspec(dllexport) runAppli(LPCSTR lpAppName)
{
// Only needed if resources are accessed
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
::ShowWindow( AfxGetMainWnd()->GetSafeHwnd(), SW_SHOW);
UNREFERENCED_PARAMETER(lpAppName);
return true;
}
|
|
|
|
|
Please put <pre> tags around your code as requested, so it is clearly readable
As to your code, this shows that you really do not understand how to create a Windows application.
You are getting the address of the runAppli() function and then calling it with "runAppli" as its input parameter, which is declared as UNREFERENCED_PARAMETER and hence has no purpose. The runAppli function itself is trying to show a window which does not exist, and using an MFC call even though the MFC environment has not been initialised. The net result is that the function will fail but will not give you any indication of why because you do not check for errors.
This program will never work however much you play with it. I would suggest you use the wizard in your Visual Studio IDE to create a proper Windows/MFC program, and examine the source and read the documentation to understand how the various pieces fit together.
|
|
|
|
|
Look Friends
Now I am not calling the dll from not winn32 but from another mfc exe application. Where I have a button when I press it I should load the dll and launch the mainwindow. See my two apis
void CClientRevProjDlg::OnBnClickedButton1()
{
typedef VOID (*MYPROC)(HWND);
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
HWND h = AfxGetMainWnd()->GetSafeHwnd();
// Get a handle to the DLL module.
hinstLib = LoadLibrary(L"C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll");
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "runAppli");
// Do add operation
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd) (h);
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("message via alternative method\n");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//And in the dll App.cpp I have an extern "C" like this....
extern "C" BOOL __declspec(dllexport) runAppli(HWND h)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// HWND h = AfxGetMainWnd()->GetSafeHwnd();
ShowWindow(h,SW_SHOW);
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
With this when I press the run button from client exe, my dll mainwindow is shown but crashing and hanging for sometime. Please help me get rid of this problem someone Thanks a lot.
|
|
|
|
|
Once again, please put <pre> tags around your code so we can read it clearly, it is not easy to understand what your code is trying to do without it.
As to your code, I still do not understand (and you have not explained) what you are trying to do with this dll; which, incidentally seems to change with every reply you post. Forget everything you have done in the past and try to explain clearly exactly what you are trying to achieve.
|
|
|
|