|
thanks Iain.I have solved the problem.
The fact that you are right!
void CMainFrame::OnBeginthread()
{
typedef void (*Pdllfun)();
HINSTANCE hdll=LoadLibrary("thread.dll");
if(hdll==NULL)
::MessageBox(NULL,"can not laod the dll","",MB_OK);
Pdllfun pdllfun=NULL;
pdllfun=(Pdllfun)::GetProcAddress(hdll,"dllext");
if(pdllfun==NULL)
::MessageBox(NULL,"can not laod the dll funion","",MB_OK);
pdllfun();
::MessageBox(NULL,"hold the dll","",MB_OK);
FreeLibrary(hdll);
}
so..thanks Iain again!!
Never Change My Goal!
|
|
|
|
|
Iain Clarke wrote: Imagine Wile E Coyote running off a cliff, running into mid air for a few seconds, looking down... that's what you've done to your code.
Excellent!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Iain Clarke wrote: I wouldn't go any near MFC for the DLL at all, just plain vanilla Win32.
If he's truly properly implemented a "regular DLL linked to MFC" as
described here[^]. there should ne no problems.
Probably some thread synchronization issues in the near future for kim_wu...
Thanks for handling the remainder of this thread!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got two questions.
1 - Which is the preferred way of using the pointer symbol(*). Is it along with the type or with the identifier?
int* intPtr
OR
int *intPtr; IMO, the second one is more clear when we declare something like this.
int *intPtr1,intPtr2; 2 - Is it a good practice to append const with member function that doesn't modify any member variables?
int foo::sampleMethod() const{
} I understand why const member functions exists. But if we are not planning to make the class object as constant, do we need this kind of declarations?
Any help would be great.
|
|
|
|
|
I personally prefer the int* intPtr; But I declare a single variable in a line. This way I can add a comment for each variable I use.
I do add const to each member function that doesn't modify member variables. The problem is you can almost never predict how the class is going to be used at a later time. Once I had to add const to loads of member function for about 10-20 classes. Also, I am not sure, but in certain cases adding const might help compiler to produce more optimized code.
-Saurabh
|
|
|
|
|
Saurabh.Garg wrote: But I declare a single variable in a line. This way I can add a comment for each variable I use.
Saurabh.Garg wrote: The problem is you can almost never predict how the class is going to be used at a later time.
Good points.
Saurabh.Garg wrote: I am not sure, but in certain cases adding const might help compiler to produce more optimized code.
Do you have any articles/books which explains this?
Thanks for your help
|
|
|
|
|
you have an interview, don't you ?
Christian Flutcher wrote: 1 - Which is the preferred way of using the pointer symbol ?
for me, I like to declare every variable separatedly, and I don't like to mix declarations of different types.
this way, I prefer using int* pi; syntax because I see immediately that pi is of type int*.
Christian Flutcher wrote: 2 - Is it a good practice to append const with member function that doesn't modify any member variables?
definitely, yes !
because the one who write the class is not always the one who will use it, a class definition has to be clear, and has to mean what the class is designed for.
When you have an accessor which just does a "get", the it's obviously not modifying the object, and should be declared as const.
Christian Flutcher wrote: I understand why const member functions exists. But if we are not planning to make the class object as constant,
humm, it seems to me that you don't fully understand the thing.
making a function member constant doesn't mean every function members have to be consts, and it doesn't mean either that the object will be used as a constant.
If you'd like to say that the object is used as a constant, then you would have to do like this :
<font color="blue">class</font> foo { ... };
<font color="blue">const</font> foo f(<font color="green"></font>);
|
|
|
|
|
toxcct wrote: you have an interview, don't you ?
No I don't have. I just finished reading "Thinking in C++" and about to start a project in C++. So thought of getting some expert advice on those points.
Thanks for you help. It was really helpful.
|
|
|
|
|
1/ I normally do:
int *pInt;
2/ the question you ask is why I never mix those. And if the variable it at all significant, it gets its own line. I use long variable names - thanks to intellitext they're just as easy to type, and a lot easier to read. Only loop vars get bunched together. int i,j,k;
3/ I try to use const on member functions that *shouldn't* modify the state, not whether I think I might do so. It gives me the freedom to change my mind in one direction, and makes it harder to code mistakes in the other.
Iain.
|
|
|
|
|
Perfect ! Thanks for the help Iain.
|
|
|
|
|
|
Can you elaborate? Format what like this?
-Saurabh
|
|
|
|
|
123456789.00
to
123,456,789.00
Just add a comma every 3 digits at the left of the decimal point.
|
|
|
|
|
Here is the correct method for displaying numerics in English_USA.1252
double dMoney = 0123456789.0123456789;
char szOldCppMoney[MAX_PATH] = {0};
char szNewCppMoney[MAX_PATH] = {0};
sprintf(szOldCppMoney,"%2.2f",dMoney);
LCID lc = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
GetNumberFormat(lc,0,szOldCppMoney,NULL,szNewCppMoney,ARRAYSIZE(szNewCppMoney));
Output will be: "123,456,789.00"
Best Wishes,
-David Delaune
|
|
|
|
|
See StrFormatByteSize if you want to use of bytes/kilobytes,...
|
|
|
|
|
I use ShellExecute() to execute some operations on a ".txt" file. But it just executed a few of them and the others returned an Error.
These operations did not work:
-------------------------------------
1- Properties
2- Delete
3- Rename
.
.
.
Any help?
Thank you masters!
|
|
|
|
|
Not all verbs are available to all files and folders.
As the docs state:
"Generally, the actions available from an object's shortcut
menu are available verbs."
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes I know! But the verbs Rename, Delete and Properties are common to all objectes. Aren't they?
|
|
|
|
|
if you want to delete/rename a file, why don't you use the dedicated API ?
|
|
|
|
|
I poked around my registry and tried a bunch of right-clicks
on files of different types...I couldn't find any type that supported
any of those.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The next question is about catching all the SETTEXT message that are sent to a specific window:
I'm trying to hook all the settext messages that are sent to a specific window. The hook works almost perfectly, it intercepts all the settext messages and gets de windows handle stored in the pwp structure. pwp is a CWPRETSTRUCT type structure that contains the information of the SETTEXT hooked message.
The problem is that I can't get the text(caption) send to the window stored in the LPARAM of the settext hooked message (pwp->lParam. I only get garbage).
The idea is to get the text send to the window and save it to a file.
Im using a CallWndRetProc hook.
Here is my code.
LRESULT CALLBACK CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
{
TCHAR *a;
FILE *f1;
if(nCode < 0)
{
return CallNextHookEx(hook, nCode, wParam, lParam);
}
if (nCode == HC_ACTION)
{
CWPRETSTRUCT* pwp = (CWPRETSTRUCT*)lParam;
UINT message = pwp->message;
if (message == WM_SETTEXT)
{
unsigned int whandle = (unsigned int) pwp->hwnd;
// globalvar contains the
// (unsigned int)window's handle I want to catch.
if (whandle == globalvar)
{
LPARAM l = pwp->lParam;
// The problem is on the next line.
// Var a only gets garbage.
a = (TCHAR *) l
f1=fopen("c:\\hook.txt","a+");
fprintf(f1,"%d %s\n", whandle, a);
fclose(f1);
}
}
}
return CallNextHookEx(hook, nCode, wParam, lParam);
}
Ignacio Rivera
Mexico
|
|
|
|
|
Could it be possible that the WM_SETTEXT you get has been "POSTED" and the buffer lParam contains a pointer at has been destroyed by the time you get the hook-call?
AtomAnt
|
|
|
|
|
Hey Friends
I need to start an SDI Application (CFormView Based) Hidden
I do not want it to display main window first & then i cann showwindow(sw_hide)
In VC++ 6.0
I could do
....
AddDocTemplate(pDocTemplate);
m_nCmdShow =SW_HIDE;
...
but now in VS 2008
it does not works
Any clue?
|
|
|
|
|
Don't use the WS_VISIBLE style when creating the window?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks
will try
it is a single document interface type application
so will try with CMainFrame & CMyFormView
|
|
|
|