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

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
lfjking
Earned some good credits
Earned some good credits
Posts: 102
Joined: Mon Nov 14, 2016 1:35 pm

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

Post 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?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
Are you doing both GUI and console application? Or the application will be the same with the switch?

Thank you.
lfjking
Earned some good credits
Earned some good credits
Posts: 102
Joined: Mon Nov 14, 2016 1:35 pm

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

Post 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.
lfjking
Earned some good credits
Earned some good credits
Posts: 102
Joined: Mon Nov 14, 2016 1:35 pm

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

Post 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!
Post Reply