|
Hi,
I'd like to know what is GNU C++ and which compilers doing this?
I really don't know what is this?
Regards,
-
When in doubt, push a pawn!
-
|
|
|
|
|
|
Hi all
I derived a class from CSocket.
I created an object of that class m_Socket.
I get error number 10022 when I call m_Socket.Create(8998,SOCK_DGRAM,NULL).
It works well on win2000, but fails on winNT dont know why ?
Any help would be greatly appreciated!
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
|
Hi
I got it..it was because the specified socket was already in use in the othe machine.
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Hello,
I am trying to send a structure using PostMessage.
My structure is of the form:
typedef DATA
{
int EventID;
CString ModuleName;
CString ThreatName;
} info;
info info_data;
PostMessage(WM_MYMSG, (info_data&)wParam,NULL);
In the recieving thread I tried this way:
info_data = (info_data&)wParam; // I am getting runtime error here.
Can anyone please help me to pass a user defined structure using PotMessage?
Thanks
Madhavi
|
|
|
|
|
Use wParam to send your structure pointer, i.e.
PostMessage(WM_MYMSG, (WPARAM)&info_data, NULL);
Note that you can only send pointer to your structure, so make sure that it is accessible in message handler.
ARSALAN MALIK
|
|
|
|
|
Hi,
Thanks for the inputs.
When i tried this way,
AfxGetMainWnd( )->PostMessage(WM_LOGMSG, 0, (LPVOID)&info_data) ;
I got this error :
error C2664: 'CWnd::PostMessageA' : cannot convert parameter 3 from 'LPVOID' to 'LPARAM'
Can you please let me know how to proceed?
Thanks
Madhavi.
|
|
|
|
|
Sorry for mistake. Use:
AfxGetMainWnd( )->PostMessage(WM_LOGMSG, (WPARAM)&info_data, NULL);
and in your message handler, type cast wParam to info_data pointer, i.e.
info *info_data = (info*)wParam
ARSALAN MALIK
|
|
|
|
|
Hi,
<br />
typedef DATA<br />
{<br />
int EventID;<br />
CString ModuleName;<br />
CString ThreatName;<br />
} info;<br />
<br />
info* pinfo_data = (info*)GlobalAlloc(GPTR, sizeof(info));<br />
AfxGetMainWnd( )->PostMessage(WM_LOGMSG, 0, (LPARAM)pinfo_data);
convert to LPARAM, not to LPVOID
allocate structure with API calls, and
free structure in target thread, not in main thread
|
|
|
|
|
Dont forget also that when using PostMessage() you cannot pass pointers to objects on the stack as they may go out of scope before your message gets processed. If you need it to be done whiel its in scope, use SendMessage()
If you vote me down, my score will only get lower
|
|
|
|
|
--------------------------------------------------------------------------------
Hello,
I am writing an application which uses two threads.
I have a list<int> variable in my Document class.
THREAD 1
In this thread, I am filling a list from back i.e pDoc->list.insert(list.begin(),data);
THREAD 2
In this thread, I am extracting each element from top of the list, and displaying it on the UserInterface i.e
data = pDoc->list.pop_front();
Display(data);
THREAD1 cotinously reads and adds data at the bottom of the list while THREAD 2 gets data from the top of the list and displays it.
Can I directly access the list memeber available in my document class as above in the two threads.
When I tried the above, it worked fine when the list had limited number say 10 to 30 records, but as the size of list was growing to say 10,000 records the program was crashing.
Can anyone please help me to solve this ?
Thanks
Madhavi
|
|
|
|
|
Your problem is that, you are using a shared resource (list) between two threads. You need synchronization between threads, so that only one thread at at time can access shared list. To achieve this, you can use CEvent , CMutex , or CSemaphore , depending on your needs and choice. See any good reference on these classes.
ARSALAN MALIK
|
|
|
|
|
You can also try to use thread-save lists. I think there are some at www.stlport.org.
Hardy.
|
|
|
|
|
Hi,
I have an application in VC++ 6.0 and Hierarchial database files for working. Plz Note, Here I am not connecting my application to any database, insteed I am using the Hierarchial database files for my application.
1. First I start my application and open the database file using open menu which intern generates the XML files from database files. On "save" the data is saved in "Workspace"
Next time when I start the application it loads the last recently saved workspace.
2. Now I starts one more instance of same application i.e. second instance of same application. Here it loads the last saved workspace (same workspace is opened in first instance ). So working on same workspace in two different instaces is dangerous for data.
I want to restrict the second instance from loading the workspace if it is already loaded in previous instance.
Also, I should be able to work on different workspaces in different application instances.
Q: How to manage this?
Plz send any samples, codes, ideas to me
Thanx for your valuable help and support.
Thanks & Regards,
Neeraj
|
|
|
|
|
Are you saving 'Workspace' as file? If yes, then while opening workspace file, open it in exclusive mode, so that access is denied to second instance of your application. For example if you are usinf CFile to open workspace use:
CFile file;
file.Open("workspace", CFile::shareExclusive|CFile::modeReadWrite);
ARSALAN MALIK
|
|
|
|
|
Thanx Malik,
I will try this and get back to you.
Thanks & Regards,
Neeraj
|
|
|
|
|
Hi
If you want to allow only one instance of your application. You can use mutex.
Create a mutex object with specific name in initinstance. If mutex creation fails means another instance is open.
Regards,
prashant
|
|
|
|
|
Use Mutex to restrict only one instance of application.
Create mutex with specific name in initinstance.
If function failed your application is already running
prashant
Regards,
Prashant
|
|
|
|
|
Thanx prashant.
Can you send me some sample code for that?
Thanks & Regards,
Neeraj
|
|
|
|
|
SECURITY_ATTRIBUTES secAttributes ;
secAttributes.nLength = sizeof (SECURITY_ATTRIBUTES);
CreateMutex (&secAttributes, TRUE, "PRASHANT" );
if (GetLastError () == ERROR_ALREADY_EXISTS)
{
::MessageBox (NULL, "Application is already running.", "PRASHANT", MB_OK | MB_ICONEXCLAMATION);
return 1;
}
Regards,
Prashant
|
|
|
|
|
Thanx Prashant.
Where exactly I have to put this code in Initinstance?
Can you give me complete Initinstance code?
Thanks & Regards,
Neeraj
|
|
|
|
|
It can be the first statement of initinstance
BOOL CMyApp::InitInstance()
{
SECURITY_ATTRIBUTES secAttributes ;
secAttributes.nLength = sizeof (SECURITY_ATTRIBUTES);
secAttributes.lpSecurityDescriptor = NULL ;
secAttributes.bInheritHandle = FALSE ;
CreateMutex (&secAttributes, TRUE, "prashant");
if (GetLastError () == ERROR_ALREADY_EXISTS)
{
::MessageBox (NULL, "Application already running", "Prashant",MB_ICONEXCLAMATION);
_exit(0);
}
//Rest of the code of initinstance
}
Regards,
Prashant
|
|
|
|
|
Prashant thanx a lot.
It's working fine. Poping the message "Application already running" when I try to start the second instance of the application.
Still what I need is, when I click the message box "Application already running", the first instance of application should be displayed on the screen.
Thanks & Regards,
Neeraj
|
|
|
|
|
Hi there
How to add a toolbars to a win32 application?
Thanks
|
|
|
|