|
well.. i am a novice as far as mfc prog is concerned.... so plz help
theres is this dialog class... CServerDlg
whose data i wanted to access from this func
unsigned WINAPI ClientThread(LPVOID threadInfo)
for which i used : CServerDlg *dlg = (CServerDlg *)AfxGetApp();
using this pointer i was accessing the data....
but thers some prob in this..and the app soon terminates.
probably this is not correct way of calling data from CServerDlg class....
plz helo with a solution to this problem
|
|
|
|
|
i suspect you to have set te data members as public inside the dialog box. you loose the use of encapsulation...
i know this doesn't solve your problem, but you could get into troubles later.
consider passing by member functions instead.
|
|
|
|
|
The problem is that AfxGetApp gets a pointer to an CWinApp instance and not a dialog class. You shouldn't be using C-style casts. If you had of used a function style cast as shown below you couldn't have made this mistake as the code wouldn't have compiled:
CServerDlg *dlg = static_cast<CServerDlg*>(AfxGetApp());
If you try to do something impossible, in a perfect world, you should get a compiler error instead of a crash: Switching to function style casts is a positive step in this direction.
In my own code I never use C-style casts.
Steve
|
|
|
|
|
This is the third time you have beaten me to it, and i forgot to mention CServerDlg as well
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Steve
|
|
|
|
|
Using MFC objects in seperate threads is not always a good idea due to nature of the library.
Instead define a struct
struct ThreadData {
};
when you create the thread
ThreadData *pData = new ThreadData;
CreateThread(NULL,0,ThreadFuncName,pData,0,&dwThreadId);
Then in the ThreadFuncName function
...ThreadFuncName(LPVOID lpVoid)
{
ThreadData *pData = (ThreadData*)lpVoid;
return 0;
}
And if u wish to communicate to some windows then use HWND's not CWnd's to send messages
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
hi all
i want to generate the code 39 barcode.i had search on the internet but could not find any algo for making the code 39 bar code any link u people visited or known.
ddd
|
|
|
|
|
|
Don't know much about bar codes but i saw this[^] once
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
How about using a font?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi,
I want to pass the reference(test) of the interface (ITest) define inside the COM DLL (TestCom.dll) in my application function.Example
GetMerchItemType( TestComLib::ITest &test, int Temp)
However I am facing the following error.
error C2653: 'TestComLib' : is not a class or namespace name
error C2061: syntax error : identifier 'ITest'
Can you please help me resolve this error.
Thanks
-- modified at 3:42 Friday 10th March, 2006
|
|
|
|
|
You have to import the typelib of the testcom.dll into your project.
|
|
|
|
|
Search for the definition of ITest . Is it enclosed in a namespace called TestComLib ? I assume you're using #import . If you are you'll need to look in the .TLH and .TLI files.
Steve
|
|
|
|
|
i want to make popu menu which show on right click of mouse how can i done it.
Bankey Khandelwal
Software Engineer
|
|
|
|
|
Add a menu, then add a submenu to the menu.
The use Classwizard to add a Message Handler for WM_RBUTTONCLICK
writting from memory s please confirm
In Handler
...::OnRclick()
{
DWORD dwMousePos = GetMessagePos();
CPoint pt(HIWORD(dwMousePos),LOWORD(dwMousePos));
CMenu menu;
menu.LoadMenu(IDR_MENU1);
CMenu *pSubMenu = menu.GetSubMenu(0);
pSubMenu->TrackPopupMenu(...);
}
hope it helps
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
<br />
VOID APIENTRY DisplayContextMenu(HWND hwnd, POINT pt) <br />
{ <br />
HMENU hmenu;
HMENU hmenuTrackPopup;
<br />
<br />
if ((hmenu = LoadMenu(hinst, "ShortcutExample")) == NULL) <br />
return; <br />
<br />
<br />
hmenuTrackPopup = GetSubMenu(hmenu, 0); <br />
<br />
<br />
TrackPopupMenu(hmenuTrackPopup, <br />
TPM_LEFTALIGN | TPM_RIGHTBUTTON, <br />
pt.x, pt.y, 0, hwnd, NULL); <br />
<br />
<br />
DestroyMenu(hmenu); <br />
} <br />
|
|
|
|
|
its done do't west ur time.
Bankey Khandelwal
Software Engineer
|
|
|
|
|
for show menu I suggestion you can use event WM_CONTEXT_MENU
void CAnswerView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu menu;
menu.LoadMenu(IDR_MAINFRAME);
CMenu *m_ContexMenu=menu.GetSubMenu(0);
m_ContextMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,point.x,point.y,AfxGetMainWnd());
}
|
|
|
|
|
hello!
I asked this question some days ago, but got no answer.
I'm stil searching for a good profiler for VS2005 Pro.
Can sombody recommend one?
|
|
|
|
|
I don't think there is a free one available, and it doesn't look like Compuware is releasing a free one for VS2005 like they did for 2003.
For a recent project, I ended up using a demo version of AQTime. A little bit quirky to use at first, but it works good once you know how to use it. Only works for 15 days.
"My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
|
|
|
|
|
Hi !
In my application, I'm making a call to a function provided by a third party library. Unfortunately, this call is crashing in some situations (which I have no way to detect prior to calling the function).
I tried to put the call into a try{} catch{} block, but it didn't work. Here is what I did :
try {
api_call(mydata);
}
catch (...)
{
// error
}
the problem is that my app keeps crashing in the 'try' block, which is something I don't understand. I'm compiling with expection support.
Any hint ?
Thanks !
Jerome
|
|
|
|
|
<br />
__try <br />
{<br />
api_call(mydata);<br />
}<br />
__except ( expression )<br />
{<br />
}<br />
|
|
|
|
|
Hi !
Thanks for your answer, but it seems __try and __except are MS specific keyword. I'm compiling in a linux environnement...
Any onther hint ?
Thanks !
Jerome
|
|
|
|
|
You could give more information, here is my guess.
If you are calling a C-function from a C++-class, you have to do this in the third party .h-file:
Surround all function declarations with this code:
#ifdef __cplusplus
extern "C" {
#endif
// the original function prototypes
#ifdef __cplusplus
}
#endif
Else, the first parameter of all function calls will be the this pointer. And that will make the funcion call to crash...
|
|
|
|
|
Hi thanks for your answer.
I'm actually calling a C++ function from a C++ class. The call to the function works in most cases, but crashes in some specific cases.
Jerome
|
|
|
|