yaa... you may be right... thank to you guys for the help...
From Indonesia with love..!!
yaa... you may be right... thank to you guys for the help...
From Indonesia with love..!!
plz help me with this code... int a = 0; int p = 2; int q = 3; a += p ? q : 0;
what does the last line mean? i need to describe it into normal if-then-else form... thanks all...
From Indonesia with love..!!
yup....i think you booth are right.. i've got some old functions which return a const char* variable... that's confusing me since i need also to modify the result... thanks kastenk thanks mark
From Indonesia with love..!!
I've got friend suggesting me to convert cons char* variable to char* by copying the data. I mean using: char *x = strdup(const char *y). But I think I can easily typecasting it, like this: x = (char *) y. Am I doing a good coding practice here because I prefer typecasting it I don't even get warning for doing this. Any way are they the same? Which one should be a good programmer do? THX!!!!
From Indonesia with love..!!
Thank you very much for your help... i think i need to learn more and more... :)
class CPROXY
{
public:
CPROXY(void);
~CPROXY(void);
int Run(int nPort);
static DWORD WINAPI MotherThread(LPVOID param);
static DWORD WINAPI DaughterThread(LPVOID param);
int MotherThreadWorker();
int DaughterThreadWorker();
int GetAddressAndPort(char \* cStr, char \*cAddress, int \* nPort);
private:
ACE\_SOCK\_Acceptor client\_acceptor;
ACE\_SOCK\_Connector server\_connector;
CRITICAL\_SECTION guard;
HANDLE wait;
bool isMotherThreadRunning;
bool isDaughterThreadRunning;
**static std::list<ACE\_SOCK\_Stream> queue;**
};
The implementation is like this:
CPROXY::CPROXY(void)
{
InitializeCriticalSection(&guard);
wait = CreateEvent(NULL, FALSE, FALSE, NULL);
}
CPROXY::~CPROXY(void)
{
}
std::list<ACE_SOCK_Stream> CPROXY::queue;
int CPROXY::Run(int nPort)
{
DWORD thid;
HANDLE hMotherThread = CreateThread(NULL, 0, MotherThread, this, 0, &thid);
if (!hMotherThread)
return -1;
ACE\_SOCK\_Stream client\_stream;
ACE\_INET\_Addr addr;
addr.set(nPort, addr.get\_ip\_address());
int e = client\_acceptor.open(addr);
if (e == INVALID\_SOCKET)
return -1;
while(true)
{
int e = client\_acceptor.accept(client\_stream);
if (e == INVALID\_SOCKET)
continue;
//Store in a buffer.
**EnterCriticalSection(&guard);
queue.push\_back(client\_stream);
LeaveCriticalSection(&guard);**
}
return 0;
}
DWORD WINAPI CPROXY::MotherThread(LPVOID param)
{
CPROXY *newobj = (CPROXY *)param;
newobj->MotherThreadWorker();
return 0;
}
int CPROXY::MotherThreadWorker()
{
isMotherThreadRunning = true;
while (isMotherThreadRunning)
{
**EnterCriticalSection(&guard);
bool isEmpty = queue.empty();
LeaveCriticalSection(&guard)**;
if (!isEmpty){
DWORD thid;
**HANDLE hDaughterThread = CreateThread(NULL, 0, DaughterThread, this, 0, &thid);**
if (!hDaughterThread)
continue;
printf("\\nWAITING!\\n");
WaitForSingleObject(wait, INFINITE);
printf("\\nFINISHED!\\n");
}
}
return 0;
}
DWORD WINAPI CPROXY::DaughterThread(LPVOID param)
{
CPROXY *newobj = (CPROXY *)param;
newobj->DaughterThreadWorker();
:
:
return 0;
}
int CPROXY::DaughterThreadWorker()
{
char buf[BUFSIZE];
char cServerAddress[256];
int nServerPort;
**EnterCriticalSection(&guard);
ACE\_SOCK\_Stream client\_stream = queue.front();
queue.pop\_front();
LeaveCriticalSection(&guard);**
SetEvent(wait);
Thank for your reply. I mean there is a main function that will call int ServerThreadRunner(). Meaning that for every thread will be handled by new CPROXY newobj pointer. So, if it is only pointer pointing the same location, does it mean that i need to put synchronization for every data member that accessed by the thread function? How about this: std::list <spair> queue;
vs std::list <spair*> queue;
which one needs synchronization, and which one doesn't need? What came to my mind is: there is no need for synchronization unless i put the queue as a static variable. am i right? static std::list <spair*> queue;
sorry if my question is not really good. i hope you understand. i can't just solve that problem by trial & error because both of them work. I need strong concept.
I have this class:
class CPROXY
{
public:
CPROXY(void);
~CPROXY(void);
int CreateConnector();
int CreateAcceptor(int nPort);
:
:
:
private:
ACE\_SOCK\_Acceptor client\_acceptor;
ACE\_SOCK\_Connector server\_connector;
**std::list <spair\*> queue;**
}
Now the implementation is like this:
int CPROXY::ServerThreadRunner()
{
:
DWORD thid;
HANDLE hServerThread = CreateThread(NULL, 0, ServerThread, this, 0, &thid);
:
:
}
DWORD WINAPI CPROXY::ServerThread(LPVOID param)
{
CPROXY *newobj = (CPROXY *)param;
newobj->CreateConnector();
return 0;
}
int CPROXY::CreateConnector()
{
EnterCriticalSection(&guard);
SPAIR *sPair = queue.front();
queue.pop_front();
LeaveCriticalSection(&guard);
SetEvent(wait\_server);
:
:
:
Take a look at queue. Queue is declared as a list of SPAIR. Do you think it is necessary for me to guard it with critical section every time is accessed by a thread? I mean, before i run the thread i did put it into a newobj, so meaning that every newobj has its own member so no need for me to put critical section to guard it, right? PLEASE, correct me if I'm wrong! i need to optimize this code.
yup, i know...i meant allocating memory for s1.. my concern wasn't on part where p=s. i thought application crashed due to NULL pointer on s1...that's why we must allocate memory for s1... :-D
allocating memory so i won't be a NULL pointer anymore... :)
try allocate memory like this: char * s_cpy(char * s,char * s1) { char * p =(char*) malloc(strlen(s)+1); s1 = (char*) malloc(10); //use this!!!! p=s; printf("%s\n",p); // prints TEST printf("%s\n",s1); // prints printf("%s\n",s); // prints TEST strcpy(s1,p); //error, test.exe has encountered a problem return s1; } don forget to free them up later or you will encounter memory leak...
how come? right click on error list then choose go to location, this should bring you to the error location... couldn't be like that... a bit strange...
this is what msdn says: A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages. check it on http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#message_only[^]
may be you can make an MDI application.. do googling about data transfer among dialogs, try to check this: http://www.functionx.com/visualc/dialog/dialog2.htm[^]
Ups, I didn't notice :laugh: ...sorry...
try muParser.. i love it.. just do googling...
i've never done programming using bluetooth before... but i suggest you ro google about mobile phone programming... find beeter API may be... try this : "http://mobile.liveshere.net/articles/viewarticle.php?id=19"
ya nice idea...but do you have any idea (link) or something wherei can learn about hook in windows...??
there is an application that keep nagging me...every time it closes, it will open my internet browser...i want to make an app with visual c++ so i can stop it opening my internet browser...can i use a hook to stop it...can anyone help me please... thx