|
I am exporting a function something like show below:
extern "C" DllExport const char* ActivatePlot(CString szPlot);
When I call this function from another DLL or module, the application crashes while returning from the function "ActivatePlot".
From the call-stack I found that the control is in the destructor of CString object and is trying to free the memory using FreeStore().
Can you explain whether we can use CString object in a DllExport functions? And if not, why?
|
|
|
|
|
CString uses dynamic memory allocation to store its strings. When you pass a CString object about, if it needs to re-allocate at any point, it will make use of the current heap manager to allocate the memory. If your doing this in MFC with the MFC library as a shared DLL, you should only have the one heap manager. If your not, then you will find that you are trying to de-allocate an allocation from one heap manager with an allocation from the other - which is probably the problem here. In such cases as this, can you not just pass in the szPlot as a const char * pointer? You need to avoid passing about objects that will do this.
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
Hi Everybody,
I have a class which is being derived from CDialog class.
class CEventDialog : public CDialog {
private:
CString m_sEventDesc;
int m_iHours;
int m_iMin;
// Other implementation has been removed from the class.
};
The deifination for DoDataExchange is as follows:
void CEventDialog::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
DDX_Text(pDX,IDC_ADDSTRHR,this->m_iHours);
DDV_MinMaxInt(pDX,this->m_iHours,1,24);
DDX_Text(pDX,IDC_EDITDESC,this->m_sEventDesc);
DDV_MaxChars(pDX,this->m_sEventDesc,20);
DDX_Text(pDX,IDC_ADDSTRMIN,this->m_iMin);
DDV_MinMaxInt(pDX,this->m_iMin,1,59);
}
The problem which i am facing is that if i enter an invalid value for iMin data variable , the DDV_MinMaxInt function displays a message box without any message in it. How should i display the used defined message in the Message Nox which is being created by DDV_MinMaxInt function?
Regards
Dinesh
|
|
|
|
|
Have you stepped into DDV_MinMaxInt() to see why it is failing to retrieve the text?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I did that :
DDV_MinMaxInt internally calls _AfxFailMinMaxWithFormat function
AFX_STATIC void AFXAPI _AfxFailMinMaxWithFormat(CDataExchange* pDX,
long minVal, long maxVal, LPCTSTR lpszFormat, UINT nIDPrompt)
{
ASSERT(lpszFormat != NULL);
if (!pDX->m_bSaveAndValidate)
{
TRACE0("Warning: initial dialog data is out of range.\n");
return; // don't stop now
}
TCHAR szMin[32];
TCHAR szMax[32];
wsprintf(szMin, lpszFormat, minVal);
wsprintf(szMax, lpszFormat, maxVal);
CString prompt;
AfxFormatString2(prompt, nIDPrompt, szMin, szMax);
AfxMessageBox(prompt, MB_ICONEXCLAMATION, nIDPrompt);
prompt.Empty(); // exception prep
pDX->Fail();
}
The prompt variable comes out to be empty. Do I have to explicitly create a String Resource and pass that resource in one of these functions ?
Regards
Dinesh
|
|
|
|
|
So what is the value of CEventDialog::iMin , minVal , and maxVal at this point?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hello,
You can try the following in the OnInitDialog:
CEdit* pEditControl = (CEdit*)GetDlgItem(IDC_EDIT1);
if(pEditControl)
{
pEditControl->SetLimitText(6) ;
}
Hope this works..
Regards,
Maheshwar.
|
|
|
|
|
Does STL string support unicode, if so how do i use it.
My God is more powerfull Than Your God. (the line that divides the world)
|
|
|
|
|
You need to use wstring.
Mike
|
|
|
|
|
std::string is a typedef for std::basic_string<char>
The typedef for wchat_t is called std::wstring.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
I am trying to get process status information(cpu time, mem usage, etc) on all processes running on my Win XP system using C.
I have elevated the privilege of the current process to SE_DEBUG_NAME, but I get ERROR_ACCES_DENIED when I call OpenProcessToken() for the the following processes:
alg.exe
svchost.exe
svchost.exe
Task Manager reports that the user names for these processes are LOCAL SERVICE, LOCAL SERVICE, and NETWORK SERVICE respectively.
My goal is to extract the user sid from the process token so that I can display the user name like Task Manager does.
My program works for all other processes (except "idle").
1) What do I have to do to access the tokens for these processes?
It seems as if my current process is denied access to the process
token if the user name is either LOCAL SERVICE or NETWORK SERVICE.
2) How do I extract the same info for the idle process?
Thanks in advance
Daniel
|
|
|
|
|
hi,
have a dialog based application in which i would like to capture the OnKetDown event...but inspite of mapping it thru the Class Wizard ...it doesnt seem to work... what is the reason.....
Satadru.
|
|
|
|
|
try PreTranslateMessage
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
i tried thid but didnt work:
BOOL ControlDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==WM_KEYDOWN)
{
MessageBox("I did it!");
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
hi..
You can use like that..
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
UINT nChar=(UINT)pMsg->wParam;
if(nChar==VK_UP )
{
}
}
return CDialog::PreTranslateMessage(pMsg);
}
good luck....
|
|
|
|
|
I am using a CListView derived class and using it as a virtual list control to display over 30,000 items from a database. Its all working very good, my only complaint is about the scrolling effect when doing a page down or page up. It looks like the whole page is scrolled (up or down) before the items are repainted and is very noticeable. I would like the view to be redrawn faster (avoiding the scroll effect). Just like when you go to the end or top, by pressing the End or Home keys.
I know that the scrolling effect is good when dragging the thumb of the scrollbar, but for page up and down, for an entire page it is not good.
Anyone knows how to get rid of the scrolling affect ?
thanks,
Louis.
|
|
|
|
|
when i use CStatic::SetBitmap, i don't know if memory leaks in my way.
could u suggest me a good way out of leaking?
Thank u very much!
my way:
CBitmap* pbmp = new CBitmap();
pbmp->LoadBitmap(someID);
pstatic->SetBitmap(*pbmp);
delete pbmp; //sometimes the line is ommitted
Hello World!
|
|
|
|
|
if you allocate memory via new operator
then you have to delete it via delete operator
otherwise memory will be leaked
in ur case delete pbmp
would be done in OnDestroy
pbmp should not be a local variable (define it in class)
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
I See.
Thank u!
Please use your head again.
if u have another good way, please tell me immediately.
Hello World!
|
|
|
|
|
why are you using new ?
in class
do
CBitmap bmp;
in Constructor
do - bmp.LoadBitmap(MY_BMP);
then
in OnInitDialog
pic.SetBitmap(&bmp);
Done!
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
if so, how to do?
i don't want to add many global variables.
Could u have some useful way?
Thank u!
Hello World!
|
|
|
|
|
i learn a little about smart points,
but i don't know how to do.
could u tell me?
Thank u!
Hello World!
|
|
|
|
|
Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window.
#include <windows.h><br />
<br />
LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM);<br />
<br />
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,<br />
int iCmdShow)<br />
<br />
{<br />
HWND hWnd;<br />
MSG msg;<br />
WNDCLASSEX wndclass;<br />
<br />
wndclass.cbSize =sizeof(WNDCLASSEX);<br />
wndclass.style =CS_HREDRAW | CS_VREDRAW;<br />
wndclass.lpfnWndProc =fnMessageProcessor;<br />
wndclass.cbClsExtra =0;<br />
wndclass.cbWndExtra =0;<br />
wndclass.hInstance =hInstance;<br />
wndclass.hIcon =LoadIcon(NULL, IDI_APPLICATION);<br />
wndclass.hCursor =LoadCursor(NULL, IDC_ARROW);<br />
wndclass.hbrBackground=(HBRUSH) GetStockObject (GRAY_BRUSH);<br />
wndclass.lpszMenuName=NULL;<br />
wndclass.lpszClassName="Window Class";<br />
<br />
wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION);<br />
<br />
if(RegisterClassEx(&wndclass)==0)<br />
{<br />
exit(1);<br />
}<br />
<br />
hWnd=CreateWindowEx(<br />
WS_EX_OVERLAPPEDWINDOW,<br />
"Window Class",
"Create Window Example",
WS_OVERLAPPEDWINDOW,<br />
0,<br />
0,<br />
400,<br />
600,<br />
NULL,<br />
NULL,<br />
hInstance,<br />
NULL);<br />
<br />
ShowWindow(hWnd, iCmdShow);<br />
<br />
while(GetMessage (&msg,NULL,0,0));<br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
<br />
return (msg.wParam);<br />
<br />
}<br />
<br />
LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch(iMsg)<br />
{<br />
case WM_CREATE:<br />
return(0);<br />
case WM_PAINT:<br />
return(0);<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
return(0);<br />
default:<br />
return DefWindowProc(hWnd, iMsg, wParam, lParam);<br />
}<br />
}<br />
Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior?
Thanks all.
Best,
Jerry
The only way of discovering the limits of the possible is to venture a little past them into the impossible.--Arthur C. Clark Toasty0.com
|
|
|
|
|
Everything looks prety good to me
Maybe try commenting out DefWindowProc() and compiling...see what happens
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
I'm pretty sure you need to add the following code to your WM_PAINT case:
PAINTSTRUCT a_stPaint;
BeginPaint( hWnd, &a_stPaint );
EndPaint( hWnd, &a_stPaint );
It's been a while since I did raw Win32, so I'm not certain.
Chris Richardson
|
|
|
|
|