|
You can think it, but it'd still be wrong.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Adding NULL to p[12] would still cause a segmentation fault (aka crash). Since the array was not declared with any bounds, it defaults to the size of the initailized string (which is 6 for "hello"). Any character that is written past that size is overwriting something in memory that may or may not be important. If it overwrites, for example, the next instruction on the stack ... you get the idea. The point is, you should always declare arrays with a size.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello,
Writing windows service in c++.Net 2005 it’s clear, but I’ve problems when I
Want to write a windows service in C++.Net 2005 but with unmanaged code.
I’ll appreciate if anyone can give me a clue/hint.
Thanks
|
|
|
|
|
yosm wrote: but I’ve problems
yosm wrote: I’ll appreciate if anyone can give me a clue/hint.
HINT: You did not state any specific "problem".
|
|
|
|
|
Hi
I know overloading is and i know overriding in virtual functions.But when i overload an overriding functions, something differnet.
<br />
#include <iostream><br />
<br />
using namespace std;<br />
class CBase<br />
{<br />
public:<br />
virtual void func(char n)<br />
{<br />
cout << "base";<br />
};<br />
<br />
};<br />
<br />
class CDerived : public CBase<br />
{<br />
public:<br />
virtual void func(int n)<br />
{<br />
cout << " derived";<br />
}<br />
};<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
CBase* BaseForDerived = new CDerived;<br />
double y=123.45;<br />
int n=100;<br />
long d= 9;<br />
BaseForDerived->func(y);<br />
BaseForDerived->func(n);<br />
BaseForDerived->func(d);<br />
CDerived x;<br />
x.func('c');<br />
delete BaseForDerived;<br />
}<br />
Here if i write virtual void func(int n) instead of virtual void func(char n) it shows me derived for all.For first 3 it shows me base the last it shows me derived.But i confused.
Does overloading a virtual function ,in derived class mean a new function declariton?
If so why it shows me for x.func('c'); derived but not BASE.
If not why this code shows me for func() base class.I gave int parameter.
I really confused.
I am looking for your answers.
Thanks.
|
|
|
|
|
Late in C++ standardisation, the type of a single-character literal was changed from int (as it is in C89) to char . You may be using an out-of-date compiler which has not yet reflected this change.
|
|
|
|
|
What you are doing is called hiding. The rules the compiler uses for resolving which method you want have problems when you do this. Scott Meyers gives a good explanation of this in his Effective C++ book.
Basically, since char and int can be implicitly casted to each other, your overload hides the method and makes it almost impossible for the compiler to pick the correct method (it is not a mind reader afterall).
To avoid this issue, write code like this instead:
class Base
{
public:
virtual void func(char n)
{
cout << "base" << endl;
}
};
class Derived : public Base
{
public:
virtual void func(char c)
{
gfunc(9);
}
virtual void gfunc(int n)
{
cout << "derived" << endl;
}
};
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello all
I am developing dialog based application. I have written a function in main dialog class and I want to access that in other classes. How to access this function in difffernt dialogs "onInitDialog()" function
regards,
Aj
|
|
|
|
|
Hey....Simply create an object to that main dialog and call the function.
If you want to call the function of main dialog from its child dialog then the child oen have a member m_pParentWnd to the MainDialog
Then simply call
m_pParentWnd->GetFunction();
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
Thanks for reply. can you please explain in detail that will help me.
I am developing dialog based application. I have written a function in main dialog class(TestDlg.cpp) on button click i am opening new dialog (Say child.cpp ) I want to access the fuction from main dialog (TestDlg.cpp) from child.cpp. How to access the function from
|
|
|
|
|
if main dialog is CMain and other class is CLocal you can use in local class CMain* m_Main=(CMain*)GetParent(); m_Main->your_variable or your_function(and also include "Main.h" in other classess)
|
|
|
|
|
I tried this
CMain* m_Main=(CMain*)GetParent();
m_Main->Test(1);
Test is function decleareed in CMainDlg;
also CMainDlg.h included in child dialog class.
it gives following errors;
'm_Main': identifier not found, even with argument-dependent lookup
'CMainDlg' : undeclared identifier
'm_Main' : undeclared identifier
left of '->Test' must point to class/struct/union
‘CMainDlg’: identifier not found, even with argument-dependent lookup
|
|
|
|
|
You shall use CMainDlg instead CMain and where you declare CMainDlg
|
|
|
|
|
Hi,
I want to add a extra button on title bar(otrh than three standard buttons) of all the application currently running. How can I do this ? this is done by another application available on Webex.com.
Regards,
Hemant Kulkarni.
|
|
|
|
|
|
|
how to display text transparently by DC?
Background of the text contains multiple colors and/or bitmaps.
Text goes cross most of colors (bitmaps) of background.
E.g.
If transparent rate is near 100%, text color on red bkgnd becomes almost red also, and on blue bkgnd almost blue.
any idea for this?
thx
|
|
|
|
|
CDC::SetBkMode(TRANSPARENT);
--
======
Arman
|
|
|
|
|
i forgot to add one line in my post:
do no use CDC::SetBkMode(TRANSPARENT) to blur my post.
here is not a place for u to show u r so clever.
i suggest u understand post before u write down ur reply.
|
|
|
|
|
I think he needs to darw a text of course(trasnparent)
|
|
|
|
|
See here
<br />
Graphics graphics2(GetDC()->m_hDC);<br />
<br />
Font font(L"System", 22);<br />
PointF point(0.0f, 20.0f);<br />
SolidBrush Brush(Color(150, 53, 97, 200));<br />
<br />
graphics2.DrawString(L"This is a test",14,<br />
&font,point,&Brush);<br />
|
|
|
|
|
Hello I would like to call DLL function with any parameters specified on runtime (some kind of rundll32 ) Input is ini file
[DllCall]
DllName=User32.dll
DllFunction=MessageBoxA
Parameters=4
Parameter1=0
Parameter2="Hello!"
Parameter3="Title!"
Parameter4=0
I would like to: 1) don't specify in my c++ all API I would like to callin future (its brr )
2) best wihout no inline, during it's not supported by Vc++ 2005 x64 compilier
(yes its possible to use external asm file in x64)
My problem is knowledge as well: I don't know how I call with any parameters (best would be something like function AddParameter(...) )
here some tutorial code
int main(int argc, char* argv[])
{
typedef PULONG (*LP)(...);
LP lp;
HMODULE m;
m = LoadLibraryA("user32.dll");
lp = (LP)GetProcAddress(m, "MessageBoxA");
lp();
FreeLibrary(m);
return 0;
}
Such method I did (useless)
int main(int argc, char* argv[])
{
DWORD aint = 0;
char someTxt[50] = "Hello!";
HINSTANCE dlScope = LoadLibraryA("user32.dll");
FARPROC rFunction = GetProcAddress(dlScope, "MessageBoxA");
DWORD outPnt;
__asm {
push aint
lea eax, someTxt
push eax
lea eax, someTxt
push eax
push aint
call rFunction
mov outPnt, eax
}
FreeLibrary(dlScope);
printf("%d", outPnt);
return 0;
}
|
|
|
|
|
Something that seems strange to me is that you don't define the types of your parameters. And the types of the parameters is very important for a function signature. So, this is a flaw I see in this design.
Also, why do you want to provide such mechanism ? The functions in the dll are known and if you want to call them, you know their prototypes. Or am I missing something ? If you could provide some informations there it will be usefull. Like explaining why do you want to achieve such a thing, maybe there is another solution.
|
|
|
|
|
yes but I would like to define them on runtime, not static.
I want this for simple scriptting language which can call any api from system.
-- modified at 6:46 Wednesday 26th July, 2006
|
|
|
|
|
There is no easy way of doing that. You'll have to use some powerfull techniques like template for example but I cannot give you a complete solution like that (I don't have one myself).
Using a dll increase a lot more the difficulty cause to load a function, you need to know its function prototype (that is statically defined) so, I don't think this is feasible.
|
|
|
|