|
this code is what I want to achieve
#include <iostream>
using namespace std;
class BaseClass
{
private:
int x;
public:
BaseClass()
{
cout << "\n BaseClass(default) called." << endl;
}
BaseClass(int x)
{
cout << "\n BaseClass(parameter) called." << endl;
this->x = x;
}
int getX()
{
return x;
}
};
class FirstClass:protected BaseClass
{
private:
int y;
public:
FirstClass(int y, int x):BaseClass(x)
{
cout << "\n FirstClass(parameter) called." << endl;
this->y = y;
}
int getY()
{
return y;
}
int getXX()
{
return getX();
}
};
int main()
{
BaseClass obj1;
BaseClass obj2(100);
cout << "\n X = " << obj2.getX() << endl;
FirstClass obj3(200, 300);
cout << "\n Y = " << obj3.getY() << endl;
cout << "\n X = " << obj3.getXX() << endl;
return 0;
}
|
|
|
|
|
So what's the problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
That should all work; what happens when you run this code?
|
|
|
|
|
When I run the code shows:
BaseClass(default) called.
BaseClass(parameter) called.
X = 100
BaseClass(parameter) called.
FirstClass(parameter) called.
Y = 200
X = 300
wich is ok
|
|
|
|
|
Excellent, you have solved your problem.
|
|
|
|
|
Hi,
I want to debug COM dll solution through another ASP.Net solution (IIS).
Solution A - COM dll which outputs 4 com dll's.
Solution B - ASP.Net which access, solution A COM dll's. This solution was hosted in IIS
Solution B I able to debug through Visualstudio->Debug->attachtoprocess->w3wp.exe
But when solution B calls COM dll which is from solution A , I cannot debug Solution A(COM Dll).
Please suggest solution for debugging.
(Usually I debug the dll solution through
VS->Project->properties->Debugging->command->setting target exe path. But here it is asp.net solution, so I don't know what to give in Target exe path)
|
|
|
|
|
I have the following code.
Why does not my x is displayed.
I do not understand, X is returned by the getX() function wich is called from the derived class SecondClass() through an object of type FirstClass().
Initialization of X was done using constructor function FirstClass(int x).
I did not want to use the initialization function like setX ().
#include <iostream>
using namespace std;
class FirstClass
{
private:
int x;
public:
FirstClass()
{
cout << "\n Default constructor FirstClass()." << endl;
}
FirstClass(int x)
{
cout << "\n Constructor FirstClass()." << endl;
this->x = x;
cout << "\n X = " << x << endl;
}
int getX()
{
return x;
}
};
class SecondClass:protected FirstClass
{
private:
int y;
public:
SecondClass(int x):FirstClass(x)
{
cout << "\n Constructor SecondClass()." << endl;
}
void printX(FirstClass& obj)
{
cout << "\n X = " << obj.getX() << endl;
}
};
int main()
{
FirstClass box1;
SecondClass box2(100);
box2.printX(box1);
return 0;
}
|
|
|
|
|
You have two instances of FirstClass here - one inside the instance of SecondClass and one is standalone. You used the default constructor for the standalone instance, which does not initialize x. You then printed this uninitialized value.
Please note that a class declaration is not the definition of a class instance!
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
your box2.printX(box1); statement is printing the garbage of box1::x.
Note there are no initialization for FirstClass::x in its default constructor.
FirstClass box1; will call default constructor for FirstClass . x is garbage here.
SecondClass box2(100); will initialize the SecondClas::FirstClass::x to 100.
box2.printX(box1); this will try to print the x in object box1, which is garbage.
|
|
|
|
|
I have a WPF application which loads two C++ DLLs. Each DLL creates a window and registers it to receive WM_DEVICECHANGE messages to detect when our hardware is connected and removed.
This works fine when using one DLL. But when we use two, the second one does not receive the expected WM_DEVICECHANGE messages. And for some strange reason, the main WPF window DOES receive them.
Does anyone know what is going on? And how to fix this?
|
|
|
|
|
Leif Simon Goodwin wrote:
This works fine when using one DLL. But when we use two, the second one does not receive the expected WM_DEVICECHANGE messages. What if you temporarily disabled the one DLL that currently works, does the other DLL then start receiving the the WM_DEVICECHANGE message?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
That is too complex to do, but if I create a dummy WPF or WinForms project using the one that did not work, it works.
|
|
|
|
|
The person who wrote the DLLs used the same name for the message window in each DLL hence the bug!
|
|
|
|
|
Hello,
i am trying to handle problem with directX 9 and code:blocks.
i searched the internet and after installing the sdk properly and used a tutorial to compile the directx code in an static control window of my winapi program. The IDE doesn't give an error, but instead of compiling a grey window the code only does a black window over the other dialog elements, who won't be compiled properly on screen. The programm doesn't shutdown and the window bar still is in function.
Does anyone knows what's to do?
Here ist the code in cuts:
void initD3D(HWND hDlg30)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hDlg30;
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hDlg30,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
}
HRESULT CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface);
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);
d3ddev->BeginScene();
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
void cleanD3D(void)
{
d3ddev->Release();
d3d->Release();
}
And this is the dialog code so far:
BOOL CALLBACK RaumkarteProc(HWND hDlg30, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
HDC hdcZeichnung;
RECT rect;
static HWND hwndRaumkarteAktion1, hwndRaumkarteAktion2,
hwndRaumkarteHScroll, hwndRaumkarteVScroll, hwndRaum;
int AnzahlGegner;
static int rightWidth=1100;
static int lowerHeight=650;
static int leftWidth=300;
static int upperHeight=50;
bool Kartezeichnen=true;
static int iAktions1index;
static int Aktion1auslesen;
static char Aktion1auswahl[100];
int Kartenmobilanzahl;
Kartenmobilanzahl=Zufallsgegner_Raum.size();
hwndRaum=GetDlgItem(hDlg30,ID_RAUMKARTE31);
initD3D(hDlg30);
switch (message)
{
case WM_INITDIALOG:
{
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Flug");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Feuergefecht");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Planet");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Handelsdock/ Basis");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Kom Kanal");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Scan");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Ladung abwerfen");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Ladung tauschen");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEAKTIONSLISTE34,LB_ADDSTRING,NULL,(LPARAM)"Runde abschließen");
return FALSE;
};
case WM_PAINT:
{
if (Kartezeichnen==true)
{
render_frame();
}
}
break;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case WM_KEYDOWN:
{
return FALSE;
}
case WM_SIZE:
{
return FALSE;
}
case VK_ESCAPE:
{
cleanD3D();
EndDialog(hDlg30,0);
return TRUE;
}
case ID_RAUMKARTEAKTIONSLISTE34:
{
if (LOWORD(wParam)==ID_RAUMKARTEAKTIONSLISTE34&&HIWORD(wParam)==LBN_DBLCLK)
{
iAktions1index=SendMessage(GetDlgItem(hDlg30, ID_RAUMKARTEAKTIONSLISTE34), LB_GETCURSEL,0,0);
Aktion1auslesen=SendMessage(GetDlgItem(hDlg30, ID_RAUMKARTEAKTIONSLISTE34),LB_GETTEXT,iAktions1index,(LPARAM)Aktion1auswahl);
if (strcmp(Aktion1auswahl, "Flug")==0)
{
Zielfadenkreuz==true;
UpdateWindow(hDlg30);
SendDlgItemMessage(hDlg30, ID_RAUMKARTEWAHLAKTIONSLISTE35,LB_ADDSTRING,NULL,(LPARAM)"Flug ausfuehren");
SendDlgItemMessage(hDlg30, ID_RAUMKARTEWAHLAKTIONSLISTE35,LB_ADDSTRING,NULL,(LPARAM)"Flugmodus beenden");
return FALSE;
}
else if (strcmp(Aktion1auswahl, "Runde abschließen")==0)
{
cleanD3D();
EndDialog(hDlg30,0);
return TRUE;
}
}
return FALSE;
}
}
break;
}
return FALSE;
}
|
|
|
|
|
Start with the obvious the line that is supposed to make the screen grey is Render_frame
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);
That function actually returns a result which isn't used in your code, so use the return and debug it
HRESULT result = d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);
Now put a breakpoint on the line and check the result is D3D_OK.
It tells you in the directx9 help for the function
IDirect3DDevice9::Clear will fail if you:
Try to clear either the depth buffer or the stencil buffer of a render target that does not have an attached depth buffer.
Try to clear the stencil buffer when the depth buffer does not contain stencil data.
Creating a Depth Buffer (Direct3D 9) (Windows)[^]
It is noted in your initD3D function it doesn't seem to do that
It is noted in you setup these two lines you appear to be missing
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
In vino veritas
|
|
|
|
|
Hello,
i tried to fix this, but it still doesn't work. I thougth about it and i guess it could be anything with the ressource file of the dialogue.
LANGUAGE 0, SUBLANG_NEUTRAL
IDD_DIALOG30 DIALOG 0, 0, 1000, 600
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Raumkarte"
FONT 8, "Ms Shell Dlg"
{
CONTROL "", ID_RAUMKARTE31, WC_STATIC, SS_BLACKFRAME, 201, 0, 800, 600, WS_EX_ACCEPTFILES | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
SCROLLBAR ID_SCROLLBARVER32, 202, 2, 19, 186, SBS_VERT, WS_EX_LEFT
SCROLLBAR ID_SCROLLBARHOR33, 222, 2, 214, 15, 0, WS_EX_LEFT
LISTBOX ID_RAUMKARTEAKTIONSLISTE34, 1, 0, 198, 183, WS_TABSTOP | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_SORT | LBS_NOTIFY, WS_EX_LEFT
LISTBOX ID_RAUMKARTEWAHLAKTIONSLISTE35, 1, 187, 198, 188, WS_TABSTOP | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_SORT | LBS_NOTIFY, WS_EX_LEFT
}
The DirectX Code should be in the Static Control "ID_RAUMKARTE31".
Maybe i have to add a parameter.
Thx & Greetings
|
|
|
|
|
I added these lines. There is still no effect. Please take a look at the code i postet with a thread i made in questions.
I think it has something to do with the way i manage the edit control where directx is supposed to render. It would be really nice if you take a look in my other thread.
Thanks a lot.
|
|
|
|
|
I have a CMFCToolbar that contains a CMFCToolBarMenuButton (which will display a drop down menu).
I add my custom button like this (not production code)
LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM)
{
UINT uiToolBarId = (UINT) wp;
if (uiToolBarId == IDR_TOOLBAR1 )
{
CMenu m_Menu;
m_Menu.LoadMenu(IDR_OUTPUT_POPUP);
MyToolbarMenuButton menuButton(ID_BUTTON32771, m_Menu.GetSubMenu(0)->GetSafeHmenu(), GetCmdMgr()->GetCmdImage(ID_BUTTON32771, FALSE), NULL, FALSE);
m_MaxToolbar.ReplaceButton(ID_BUTTON32771, menuButton);
}
return 0;
}
Eventually, in the framework, I get to this function :
int CMFCToolBar::InsertButton(const CMFCToolBarButton& button, INT_PTR iInsertAt)
{
/1/ CRuntimeClass* pClass = button.GetRuntimeClass();
ENSURE(pClass != NULL);
/2/ CMFCToolBarButton* pButton = (CMFCToolBarButton*) pClass->CreateObject();
ENSURE(pButton != NULL);
ASSERT_VALID(pButton);
pButton->CopyFrom(button);
INT_PTR iIndex = InsertButton(pButton, (int) iInsertAt);
if (iIndex < 0)
{
delete pButton;
}
return(int) iIndex;
}
Question:
If I understand correctly the code at line 1 and 2 in CMFCToolBar::InsertButton, it will loose all information about my own derived class MyToolbarMenuButton by getting the Runtime class and casting that to the base class ?
The issue is that I want to override some virtual method in CMFCToolBarButton but when I add my own class, it is not actually "instantiated".
Thanks.
I'd rather be phishing!
|
|
|
|
|
Hello there. I am trying to call a C function in my newly created Dll project's code. But doing so produces Unresolved External Symbol error. Here is the what I am trying
Header.h
int call_main(int argc, char** argv);
Header.cpp
int call_main(int argc, char** argv)
{
return 0;
}
Now I include this Header.h in my Dll's main file and try to call call_main . Building the project produces the said error.
<h1>include "Header.h"</h1>
class Functions
{
public:
static __declspec(dllexport) int Call_MyMain(char **argv);
};
int Functions::Call_MyMain(char **argv)
{
return call_main(8, argv);
}
What could be wrong? What am I missing? Thanks for any input.
|
|
|
|
|
You need to include the object module of header.cpp inside the build of your dll.
|
|
|
|
|
I don't know what does this mean? How do I do that?
|
|
|
|
|
...means your dll project should be building header.cpp... which produces an object file.
|
|
|
|
|
It is building header.cpp and it also produces an object file
|
|
|
|
|
If you actually compiled one as C and the other as C++ (or the other way around), you'll also have to deal with name mangling...
Standard C++[^]
If they're both C++, it's actually still possible to screw up the mangling, I believe Studio allows you to set the mangling mode to each file independently (haven't used Studio in a while though).
Decorated Names[^]
|
|
|
|
|
i think You need to include the object module of header.cpp inside the build of your dll.
|
|
|
|
|