|
I tried first link only. But cant get second instance.
Can you explain it in detail?
|
|
|
|
|
Hi ,
How will u get second instance?
those articles tell u abt preventing the second instance from running when there is already one instance running on ur desktop....
ok.........
vinsankar
|
|
|
|
|
There are no direct APIs or functions to identify which is second instance or third instance and so on.
Why do u need second instance?
What exactly is the problem u r facing?
If something is crashing in the ExistInstance in the second time, you have to find out which statement is crashing.
It may be because, u r trying to access an un initialized variable there which may get initialized in the first instance as InitInstance will execute completely in the first instance.
But in the second instance you may bypass those initializations and exits after the 'previous instance' checking. Then when control reaches ExitInstance it will crash as what ever u r accessing is not initialized. Just a thought. chk it out.
Cheers..Milton KB.
|
|
|
|
|
Hi,
Sorry.......
I don't need the second instance......I want to prevent all other instances while one is there..
then.....
I fix it .....
I made a mistake in the "return statement" after finding the previous instance of that program in the 'InitInstance()' of my App class.
I was written like this...
BOOL CMyApp::InitInstance()
{
if(IsthereApreviousInstance(....GUID))
{
AfxMessageBox("Already one Instance");
return FALSE; // This is wrong
}
}
The above code will work but an exception will raised...
So I put it like this....
exit(0); // in place of "return FALSE"
Ok.............Thanks....to all
vinsankar
|
|
|
|
|
When the first instance starts execution, the very first thing it should do is check for a mutex, if not found it should create one. When the second instance starts, it should check for the mutex, when it finds it it should terminate.
Look at the CreateMutex() and GetLastError() functions.
I'm not sure where to do this in MFC, but in Win32 these routines are the first to be executed in WinMain() . Also note all of this should be done before creating/reading any other variables.
I have a header file containing all these functions and a few more like handling Command line paramaters, and handling MultiUser/MultiDesktop environments. (A modified combination of CP examples). If you like I will send it to you.
|
|
|
|
|
Hi,
I solve it ....
See my previous message....
Thanks....
-- modified at 11:31 Monday 14th August, 2006
vinsankar
|
|
|
|
|
Vinod A Sankaranarayanan wrote: How will u get second instance?
that's why I wanted you to explain in detail.
Anyway you solve your problem, and shared,too.Thats good.
|
|
|
|
|
Hi,
I have to copy the data pointed by "void*" to a CString object.
Which is the best way?
code:
void* pVoid = 0;
CString csData;
pVoid = new BYTE(100);
// Do some thing
// ??? (Here I have to copy data from void* to CString.)
delete[] pVoid;
AfxMessageBox( csData );
Thnx in advance.
|
|
|
|
|
Use a typecast i.e.
csData = (char*)pVoid;
You should probably validate the data in pVoid first, not sure how CString would respond if the data wasn't NULL terminated.
|
|
|
|
|
void* pVoid = 0;
CString csData;
pVoid = new BYTE(100);
I would do the following:
memcpy(&csData, pVoid, 100);
//I would use a #define for the 100 tho because it make sit easier to understand
Now this has copied the data from one object to another WITHOUT using a reference.
|
|
|
|
|
DO NOT USE THE IMMEDIATE ABOVE SUGGESTION; it will result in a buffer overrun and is VERY poor coding practice.
Two general methods:
1) Cast the void pointer to a char, tchar or wchar_t pointer.
2) Call CString::GetBuffer() with the length of buffer you require. Copy the data in and then call CString::ReleaseBuffer().
You will want to to the latter if your buffer contains multiple zero terminated strings since method one will terminate the copy at the first null.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
Can anyone please help me implement a custom (override) DrawItem method for a multicolumn CListCtrl, in particular for the individual columns / subitems? Here's what I have so far:
<br />
void CColoredListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)<br />
{<br />
CString csItemText = GetItemText(lpDrawItemStruct->itemID, 0);<br />
CDC dc;<br />
<br />
dc.Attach(lpDrawItemStruct->hDC);<br />
<br />
COLORREF crOldTextColor = dc.GetTextColor();<br />
COLORREF crOldBkColor = dc.GetBkColor();<br />
<br />
if (lpDrawItemStruct->itemData != NULL)<br />
dc.SetTextColor((COLORREF)lpDrawItemStruct->itemData);<br />
<br />
if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED))<br />
{<br />
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));<br />
}<br />
else<br />
{<br />
if ((lpDrawItemStruct->itemID % 2) == 1)<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_BTNFACE));<br />
else<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_WINDOW));<br />
}<br />
<br />
dc.DrawText(csItemText.GetBuffer(), csItemText.GetLength(), &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);<br />
<br />
dc.SetTextColor(crOldTextColor);<br />
dc.SetBkColor(crOldBkColor);<br />
<br />
dc.Detach();<br />
}<br />
I'm having trouble with the very first line in this method. It always gets the itemtext of the first column, but I'm having a multicolumn listctrl so I also need to know which subitem to get. This method is called from calls to CListCtrl::InsertItem and CListCtrl::SetItemText which get called in a multithreaded context. I was hoping the LPDRAWITEMSTRUCT would have subitem info but it doesn't seem to.
Also, does the lpDrawItemStruct->itemData member contain the info that was set by calls to CListCtrl::SetItemData??
|
|
|
|
|
|
|
Dear,
I am trying to write a program that can access to other computer in my LAN with a specified user name and password. Please show me how to do this. I am working with C API.
Thank you very much.
Sincerely
Thangnvhl
|
|
|
|
|
Hope what u need is to access the file system on the remote computer.
For this u have to impersonate the user context of ur application to a user who has acceess on the remote machine.
So by using the username and password u have, call LogonUser API.
Then call ImpersonateLoggedOnUser by passing the tocken u received as out from LogonUser.
Once impersonataed, eitehr u can use the unc path to access the remote file system, or if it not shared u can use the default NT share c$, d$ etc for each drive.
cheers Milton KB
|
|
|
|
|
It's really worked.
Thank you so much
Sincerely
Thangnvhl
|
|
|
|
|
I am verry sorry. I try to create one program and it really worked at only my computer with current user. I could not connect to other computers, even my localhost with other accounts. LogonUser always returned FALSE. Please could you give me some code. Needn't API, non MFCs are OK.
Sincerely
Thangnvhl
|
|
|
|
|
I am verry sorry. I try to create one program and it really worked at only my computer with current user. I could not connect to other computers, even my localhost with other accounts. LogonUser always returned FALSE. Please could you give me some code. Needn't API, non MFCs are OK.
Thank you very much.
Sincerely
Thangnvhl
|
|
|
|
|
I want load items from database fast ! you have any ideea how ?
Because my database contain 500-1000 data it is slow when i loaded in my CListCtrl ( 3 -> 6 minutes ) i want to load them more fast... how?
this is my code when i load them :
void CMyList::FillList()
{
CData *pData = new CData();
pData->Open();
CString sNrInregistrare;
if (pData->GetRecordCount())
pData->MoveFirst();
while(!pData->IsEOF())
{
int nItem = m_list.GetItemCount();
sNrInregistrare.Format("%d",pData->m_name);
m_list.InsertItem(nItem,sNrInregistrare);
m_list.SetItemText(nItem,0,pData->m_name);
m_list.SetItemText(nItem,1,pData->m_city);
pData->MoveNext();
}
pData->Close();
}
Please help !!!!!!!!!!!!!
Thank you !!!!
-- modified at 3:00 Monday 14th August, 2006
Bravoone
|
|
|
|
|
How do you use for read from database is this your code?
|
|
|
|
|
yes is my code !
Bravoone
|
|
|
|
|
One way is prasad_som answer one way is insert your code to a thread
|
|
|
|
|
One strategy would be like this..
dont fetch all the data at one time. You must know no of rows for that.
First insert empty rows,equal to number of records.
now bring data from database, that would be visible(say its will be 6-7 rows or more). Keep other rows empty.When you make other row visible by scrolling, bring data for those rows ,too.
This way you can avoid fetching bulk data from database at one go.
|
|
|
|
|
Hi, i just created a setup file for my program. How can i create an uninstall file that will be located in the program's folder?
|
|
|
|