|
Mike Landis wrote:
Can you post example code or suggest a URL where strncpy is used to solve the longevity problem? I tried boosting the pool size to 12, just to see if it made any difference. It didn't. I am fairly convinced that defeating buffer release will solve this. The application is stable elsewhere.
It's quite late in my timezone, so I'll do that in circa 10 hours. I'm still not sure if this will work, but I'll give it a try.
If you find something that gets me valid CString's from GetItemText in the CustomDraw routine, I owe you $100.
Can't accept that - help is 100% free at CodeProject
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
Mike Landis wrote:
On subclassing, I've been using the Wizard to define classes. Finish the dialog in the resource, Ctrl-W, New class, etc. I think it's sewn together right. If you bring up the Wizard over any of my dialogs, you immediately see the subclass, messages, member functions...
Yes, but this only takes care of subclassing the *dialog*. If you want to handle reflected notifications in list control, you'll also have to subclass it. Otherewise, nobody will scan its message map - it'll be plain Win32 control with no MFC window procedure behind. I guess haven't used ClassWizard's 'Member Vars' tab to associate CYourListCtrl with any control ID. How does DoDataExchange looks like in your dialog? It should have something like DDX_Control(pDX, IDC_LIST1, m_lst1);
Can you post example code or suggest a URL where strncpy is used to solve the longevity problem?
strncpy, or rather wcsncpy - because WinCE is Unicode only - skips over longevity. In your approach, you're trying to keep string data for some time, and you're just setting item.pszText to point inside your pool. But when your LVN_GETDISPINFO handler is called, list control itself has initialized pszText. It points to its internal buffer, managed by Windows. You can create the string you need on the fly, and instead of stuffing it into pool copy it into this buffer using wcsncpy. Here how it looks in my test app running just fine on hp1910:
void CTestListCtrl::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
LV_DISPINFO* pdi = (LV_DISPINFO*)pNMHDR;<br />
if (LVIF_TEXT & pdi->item.mask)<br />
{<br />
CString strItem;<br />
strItem.Format(_T("Item %d - %d"), pdi->item.iItem, pdi->item.iSubItem);<br />
<br />
wcsncpy(pdi->item.pszText, strItem, pdi->item.cchTextMax);<br />
}<br />
*pResult = 0;<br />
}
You don't care about the lifetime of strItem, because it is copied before leaving OnGetdispinfo.
I'm sending the source of my test app to your email account. It's 12 kb zip file; solves all problems you've reported (handles NM_CUSTOMDRAW/LVN_GETDISPINFO in list control class and changes colors of list items).
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
BTW, I have just noticed that you're casting CWnd* returned from GetDlgItem to CListCtrl-derived class. This may also contribute to your problem. Usually, one would have a dialog member represeting list control, connected to actual HWND with SubclassDlgItem or DDX_Control.
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
We have a multithreaded application, in which multiple threads call a function which has an win32 api CreateDirectory( ).
We observe a stack overflow at a location in ntdll.dll which raises from createdirectory( ) api further calling many other functions in Kernel32.dll and ntdll.dll...
When I attach the process to debugger(windbg ) and put a breakpoint at CreateDirectory( ) ,the control of the execution comes there and when proceeded, stack overflow is not observed..
without a breakpoint, if we try to proceed after attaching to the process, we get a stack overflow from this api at the internal function in ntdll.dll..
we tried out two options
1) By increasing this thread stack size from default 1MB to 10MB(as we saw, one system needs more than 3MB which was sufficient in many system). This increases the stack size of the thread and the Stack overflow is overcome..
Here the question is How a thread of a particular stack size undergoes a stack overflow in one h/w configuration and doesn't stack overflow in other hardware configurations...OS in all the h/w configuration is Win2K_English..
same case with winXP OS too..
2) By putting a sleep(1) ,delay of 1ms before the CreateDirectory( ) api on assumption of a timing issue..
These two options seems to work, but we are not sure on how it circumvents the stack overflow problem..
Any lights on this issue is highly appreciated.
Regards,
Shiva P
|
|
|
|
|
Is there some reason you don't synchronize access to the CreateDirectory() call?
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Thanks for your reply..
Sure..I do use a critical section locking mechanism..
Lock();
CreateDirectory(..,..);
Unlock();
|
|
|
|
|
Dear Shiva,
I too experianced the stack correption problem in one of my projects. The reason was, if you had classes of big size, dont create then on stack, but create them on heap.
Another possible reason may be with exception handling. In our project we are throwing an exception object which is very big in size. So when the system enters into a funciton, it calulate the maximum stack that is needed. So, in exception handling mechanism, we throwed the same object many number of times in the same function, when some error cases come. In our sense as only one throw can work at a time, the system will calculate the stack size with that single exception object. But C++ calculates the stack size as ( total number of throw objects * size of single object ). thats the reason.
Hope this can help you.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Do anyone how to make a simple application to link a computer to a mobile phone using visual c++. If anyone has an idea or knows the source code for it can u please help me out.
Thanks!!
|
|
|
|
|
What mobile phone model are you talking about ?
Nokia releases and upkeeps the Nokia PC Connectivity SDK, which allows you to programmatically control a phone connected to your computer via Nokia serial cable, USB cable, Bluetooth or IrDA.
I believe Ericsson and other manufacturers have similar SDKs. They all come with a proper documentation and lots of examples. Consult these for more help.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi
I am getting list of files in given directory using FindFirstFile() and FindNextFile() function. But it shows directory as well as files. How can I know that which one is file and which one is directory ?
Or
Is ther any specific function which gives only files or only directory ?
Plz Help me.
I am in Hurry...
Thanking you
Atmiya
|
|
|
|
|
If you read the documentation in MSDN for FindNextFile you will see that the second parameter is a pointer to a WIN32_FIND_DATA structure. That structure first member is dwFileAttributes . All you do is check if the FILE_ATTRIBUTE_DIRECTORY bit is set. If it is, you have a directory, else you have a file.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
U can use..
if(GetFileAttributes(file_r_dir_name) == FILE_ATTRIBUTE_DIRECTORY)
{
//it's a directory
}
else
{
//it's a fil
}
|
|
|
|
|
Won't work as expected. You have to check the FILE_ATTRIBUTE_DIRECTORY bit only. Directories can be hidden, compressed, readonly etc.
if (GetFileAttributes(file_r_dir_name) & FILE_ATTRIBUTE_DIRECTORY)
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi !
I create a UI Thread in my software and I am sure that it is created because I have a breakpoint in the InitInstance function which only Return TRUE; At this point, I know that the message pump of this thread is running. (Is it right ?)
I use PostThreadMessage() to send a user message to my thread. It seems that the message is never sent. I try to use SPY++ with this thread and I don't find them. I find the main thread of my software but not the UI Thread created by me (This is a derivative of CWinThread). I want to see all messages for this thread in SPY++. I use it for the first time and I understand how it work which other thread and process. It does'nt work for my thread.
Do you have any idea ?
|
|
|
|
|
Danny Gilbert wrote:
At this point, I know that the message pump of this thread is running. (Is it right ?)
No, the message loop does not begin until after InitInstance() returns. If it returns FALSE, the message loop is never entered.
Danny Gilbert wrote:
I use PostThreadMessage() to send a user message to my thread. It seems that the message is never sent.
What did PostThreadMessage() return? Show us the code you used to call PostThreadMessage() .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thanks Ryan !
My InitInstance() function is the one given by Wizard. It returns TRUE and it works. (I saw it with debugger).
Here is a part of my code.
// Create Thread.
m_pUIThreadTestPlan = (ThreadTestPlan *) AfxBeginThread( RUNTIME_CLASS(ThreadTestPlan));
// Start the execution of all activities in the thread.
m_pUIThreadTestPlan->PostThreadMessage( WU_UITHREAD_TESTPLAN_START, 0, (LPARAM) thread_info);
thread_info is a structure with some information for the thread.
Here is the message map for the handler of my WU_UITHREAD_TESTPLAN_START message.
BEGIN_MESSAGE_MAP(ThreadTestPlan, CWinThread)
//{{AFX_MSG_MAP(ThreadTestPlan)
ON_THREAD_MESSAGE(WU_UITHREAD_TESTPLAN_START, OnStart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
And for sure, I have a function named OnStart().
LRESULT ThreadTestPlan::OnStart(WPARAM, LPARAM lp)
{
// Something inside here.
With my debugger I never ENTER here. NOTHINGS HAPPEN.
}
The other point is I don't see The THREAD in SPY++.
|
|
|
|
|
Danny Gilbert wrote:
The other point is I don't see The THREAD in SPY++.
Hmmm, this seems to suggest that the thread doesn't exist. Spy++ should be able to see it if it's there... Are you sure the thread is being created correctly?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ok thank you Ryan ! I found the result on www.MSDN.com
Here is the result.
// Generated message map functions
//{{AFX_MSG(ThreadTestPlan)
afx_msg LRESULT OnStart(WPARAM, LPARAM lp);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
static UINT NEAR WM_TEST_PLAN_START = RegisterWindowMessage("WM_TEST_PLAN_START");
I register my message and I call the message handler (my function) via message map with ON_REGISTERED_MESSAGE.
ON_REGISTERED_MESSAGE(WM_TEST_PLAN_START, OnStart)
I hope it won't generate another error.
|
|
|
|
|
Can anyone plz tell me how to use a function which is taking parameter as UNICODE into ANSI or such that it takes parameter as char. Or How to convert parameter from char UNICODE and UNICODE to ANSI ?
I am using function NetShareEnum : the example is same as given in MSDN. Also given below... What needs to be changed so that I can use main() instead of wmain() like...void main(int argc, char* argv[])...instead of (int argc, TCHAR* argv[])...
#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>
void wmain( int argc, TCHAR *lpszArgv[ ])
{
PSHARE_INFO_502 BufPtr,p;
NET_API_STATUS res;
LPTSTR lpszServer = NULL;
DWORD er=0,tr=0,resume=0, i;
switch(argc)
{
case 2:
lpszServer = lpszArgv[1];
break;
default:
printf("Usage: NetShareEnum <servername>\n");
return;
}
//
// Print a report header.
//
printf("Share: Local Path: Uses: Descriptor:\n");
printf("---------------------------------------------------------------------\n");
//
// Call the NetShareEnum function; specify level 502.
//
do // begin do
{
res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
//
// If the call succeeds,
//
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
{
p=BufPtr;
//
// Loop through the entries;
// print retrieved data.
//
for(i=1;i<=er;i++)
{
printf("%-20S%-30S%-8u",p->shi502_netname, p->shi502_path, p->shi502_current_uses);
//
// Validate the value of the
// shi502_security_descriptor member.
//
if (IsValidSecurityDescriptor(p->shi502_security_descriptor))
printf("Yes\n");
else
printf("No\n");
p++;
}
//
// Free the allocated buffer.
//
NetApiBufferFree(BufPtr);
}
else
printf("Error: %ld\n",res);
}
// Continue to call NetShareEnum while
// there are more entries.
//
while (res==ERROR_MORE_DATA); // end do
return;
}
|
|
|
|
|
The easiest way is to #include <AtlConv.h> and use the A2W macro.
USES_CONVERSION;
res = NetShareEnum (A2W(lpszServer), 502, ...
Look up "ATL and MFC String Conversion Macros" in MSDN.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
In my app i have a bitmap button
i set the bitmap of the button like so
m_BrowseFile.SetBitmap( LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDB_OPEN ) ) );
now in the bitmap file the background is gray, and that gray area is showing up
how do i get rid of the gray background?
|
|
|
|
|
Use LoadImage() instead of LoadBitmap() , and specify the LR_LOADMAP3DCOLORS and LR_LOADTRANSPARENT flags.
m_BrowseFile.SetBitmap((HBITMAP)LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDB_OPEN),
IMAGE_BITMAP,
0, 0,
LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
In my project, I need to automate the process of building a new network connection. You can manually set up a new connection as the following: "Control Panel" -> "Network Connections" -> "Create a new connection" -> Click "next" -> "setup an advanced connection" -> next -> ... We can assume that it is fixed process.
Is there any scripting tool or Windows API which I can use to automate the above process in my VC++ program? Anybody can give me a hint? Thanks a lot
-Jeff
|
|
|
|
|
Hi Jeff,
You can use the RAS API (Remote Access Service) to solve your problem. There's examples how to use it in MSDN.
Cohen
|
|
|
|
|
HI~
struct b
{
LPWSTR c;
}
struct a
{
b* d;
}
a* e;
e = new a[100];
a f;
f.d = new b[1000];
b g;
g.c = _T("HIHI");
f.d[0] = g;
e[0] = f;
if I delete pointer e by this statement:
delete [] e;
can it free all the memory including the dynamic array (pointer d) in structure a and the LPWSTR type string pointer in structure b?
or I need to free pointer d first or free pointer c first?
thanks
|
|
|
|