Page 1 of 1

[Help] How to use DLL with wxSocketClient in the console program

Posted: Thu Jan 18, 2018 8:50 pm
by lfjking
My ATL dll used wxsocketClinet. but now the program need in console.
but. I can't Initialize in the Main......
How can I do Now?

Re: [Help] How to use DLL with wxSocketClient in the console program

Posted: Fri Jan 19, 2018 3:49 pm
by ONEEYEMAN
Hi,
Are you doing both GUI and console application? Or the application will be the same with the switch?

Thank you.

Re: [Help] How to use DLL with wxSocketClient in the console program

Posted: Sat Jan 20, 2018 4:36 am
by lfjking
ONEEYEMAN wrote:Hi,
Are you doing both GUI and console application? Or the application will be the same with the switch?

Thank you.

My previous project was GUI, so I encapsulated my own network communication into ATL DLL(dll only use wxsocket).
But now the project is only on the console. And only use the network communication in my DLL,
But it is not possible to initialize wxSocket in the console.
So I want to ask what the solution is.
by the way:
My DLL declares the function Initialize and UnInitialize

Code: Select all

void Initialize (){wxSocketBase::Initialize();}
void UnInitialize (){wxSocketBase::Shutdown();}
so I want to use both gui and console with my dll.

Re: [Help] How to use DLL with wxSocketClient in the console program

Posted: Tue Jan 23, 2018 1:34 am
by lfjking
Thanks for doublemax !
Let me solve this problem.
if the program is Not GUI. so this's not the wxApp::OnInit(), so I must Init wxwidgets myself.
so in the console program, I can do this:

Code: Select all

int _tmain(int argc, _TCHAR* argv[])
{
	//Init wxwidgets first, then Init wxsocket
	wxInitialize();
	wxSocketBase::Initialize();


	// do something.........

	//the end release them.
	wxSocketBase::Shutdown();
	wxUninitialize();
	return 0;
}
if in dll. I can do this:

Code: Select all

int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	hInstance;
	switch(dwReason){
	case  DLL_PROCESS_ATTACH:{
		wxInitialize();
		wxSocketBase::Initialize();
		break;}
	case  DLL_PROCESS_DETACH:{
		wxSocketBase::Shutdown();
		wxUninitialize();
		break;}
	}
	return 0; 
}

so, I can use the wxwidgets in everywhere what I need!