|
Hello,
I am trying to create a instance of my class in case structure with the following code:
void CAppliDlg::OnOK()
{
switch (choice){
case 1:
m_Result.SetWindowText("Choice 1 is made");
//Create instance of my class here, the error comes from here.
MyClass aMyclass;
break;
case 2:
m_Result.SetWindowText("Choice 2 is made");
break;
case 3:
m_Result.SetWindowText("Choice 3 is made");
break;
default:
break;
}
}
It gives me a error:"initialization of 'MyClass' is skipped by 'case' label", can someone kindly figure out what the problem could be?
Thanks!
|
|
|
|
|
|
Thanks;)
But my purpose is to create the instance only within that case condition...
With a bracket it works now.;)
|
|
|
|
|
put brackets around the contents of "case 1" :
switch(...)
{
case 1:
{
stuff
}
break;
case 2:
break;
}
-c
When history comes, it always takes you by surprise.
|
|
|
|
|
With brackets it works!
Thanks!
|
|
|
|
|
I have written a DLL (Win 32) which has been compiled using VC++6 on a Windows 2000 PC. The program that is using the DLL is written in TestPoint (which you probabily won't of heard of) and when I run it on a Windows 98 machine it accesses the COM port correctly.
The problem is that we have just upgraded to a Windows 2000 PC and now the DLL will not work. The DLL is called correctly but no activity on the port occurs (we have checked using a scope).
My DLL code looks like this.
extern "C" _declspec(dllexport) long int BiPhase(int comm_port, int command, int value_1, int value_2 )
{
CComms Comms;
char OutBuffer[5];
char InBuffer[5];
char *pOutBuffer;
char *pInBuffer;
short int tries;
int ierror;
int return_value;
unsigned long Bytes_Avail, timer_loop;
unsigned char Character_0, Character_1, Character_2, Character_3, Character_4;
pOutBuffer = &OutBuffer[0];
pInBuffer = &InBuffer[0];
OutBuffer[0] = 1;
OutBuffer[1] = 7;
OutBuffer[2] = command;
OutBuffer[3] = value_1;
OutBuffer[4] = value_2;
Write the 5 bytes os data using .....
Write to Port
!WriteFile(idComDev, pb, 1, &dummy, NULL)
Read the 5 bytes of Data using ...
Read Port
!ReadFile(idComDev, &szChar, 1, &bytesRead,NULL)
Character_0 = InBuffer[0]; // Not interested
Character_1 = InBuffer[1];
Character_2 = InBuffer[2];
Character_3 = InBuffer[3];
Character_4 = InBuffer[4];
return (Character_2 * 256) + Character_1;
And my Comm port is set up as follows
DCB dcb = { 0 };
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 115200;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.fBinary = TRUE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fInX = FALSE;
dcb.fOutX = FALSE;
DWORD dwInQueue = 500000;
DWORD dwOutQueue = 5000;
COMMTIMEOUTS m_TimeOuts;
m_TimeOuts.ReadIntervalTimeout = 30;
m_TimeOuts.ReadTotalTimeoutConstant = 250;
m_TimeOuts.ReadTotalTimeoutMultiplier = 2;
m_TimeOuts.WriteTotalTimeoutConstant = 250;
m_TimeOuts.WriteTotalTimeoutMultiplier = 2;
Set up Port
CString sPort;
sPort.Format(_T("\\\\.\\COM%d"), com_port);
idComDev = CreateFile(sPort, // communication port string (COMX)
GENERIC_READ | GENERIC_WRITE, // read/write types
0, // comm devices must be opened with exclusive access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, // Async I/O
0); // template must be 0 for comm devices
Read Port
!ReadFile(idComDev, &szChar, 1, &bytesRead,NULL)
Write to Port
!WriteFile(idComDev, pb, 1, &dummy, NULL)
Any help would be greatly appreciated.
|
|
|
|
|
The obvious question "Are you sure the COM port is working?" I always use Hyperterminal and a loop back connector, a paper clip, a metal one of course;), between pins 2 & 3, hit some keys do they echo back
Checking one of my progs I use CreateFile("COM1" . . . not \\.\COM1 apart from that I can't see any possible "faults"
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
I have tested the com port by writing a Visual C++ program using the same setup as the DLL and that works.
|
|
|
|
|
In that case you have "solved" it, looks like the TestPoint program is not working on 2000 or there is a bug in it which was "ignored" by 98. Another test is to try it on XP, if it works then it is possibly a 2000 problem.
Happy hunting!
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Hi
Does anyone know how to put text on a label field into bold?
Thanks for the effort
Greetz
Jens
|
|
|
|
|
1) Create Bold Font.
2) Use SetFont to set it.
|
|
|
|
|
yes i know
i used a LOGFONT for my new font but i want it to be set on initdialog when the dialog shows, and you don't have a CDC pointer available in that function.
I have it like this:
LOGFONT logFont;
logFont.lfHeight = 8;
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = FW_BOLD;
logFont.lfItalic = 0;
logFont.lfUnderline = 0;
logFont.lfStrikeOut = 0;
logFont.lfCharSet = ANSI_CHARSET;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = PROOF_QUALITY;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
strcpy(logFont.lfFaceName, 'Times New Roman');
CFont font;
font.CreateFontIndirect(&logFont);
CFont* oldFont = pDC->SelectObject(&font);
m_FuncNedCtrl.SetWindowText("Example");
pDC->SelectObject(oldFont);
|
|
|
|
|
You want CWnd::SetFont / WM_SETFONT, rather than CDC::SetFont...
Iain,
|
|
|
|
|
Instead of:
CFont font;
font.CreateFontIndirect(&logFont);
CFont* oldFont = pDC->SelectObject(&font);
m_FuncNedCtrl.SetWindowText("Example");
pDC->SelectObject(oldFont);
Do this:
static CFont font;
font.CreateFontIndirect(&logFont);
m_FuncNedCtrl.SetFont(&font);
Regards,
Alvaro
Quitters never win. Winners never quit. But those who never win and never quit are idiots. -- despair.com
|
|
|
|
|
Another newbie question
I've got a pointer to a custom CWnd derived class, called CMyWnd. This class is created using the vc resource editor, the resourceID is IDC_MY_WND.
CMyWnd* pMyWnd=new CMyWnd(&parent);
How can I attach this CWnd to the parent CDialog, in such a way that the create method uses the data I've declared inside the resource editor?
CWnd::Create(...) asks for a CRect, windowtype and a windowtitle, but I've already declared them in the resource editor. I want to use them here.
How do I do this?
tnx.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
I don't think MFC lets you attach a dialog resource to a CWnd derived class, there must be some problem in the code there. If the 'data inside the resource editor' refers to the dialog item you have created, you should derive your class from CDialog instead of CWnd. So that you can call Create() to create a non-modal dialog box (and attach it to a parent CDialog maybe)
|
|
|
|
|
I want to get the the path where the EXE is running. Then, I'm using the GetCurrentDirectory function, but when I running the app EXE from a shortcut, it returns another directory, different of the correct directory.
Any idea or another function ??
Thanks,
Cris.
|
|
|
|
|
The GetCurrentDirectory function returns the directory which was supplied to the CreateProcess call as a parameter and it seems like the windows shell supplies different arguments depending on conditions (which is for example the case if you've auto-run your application through the registry key with windows/currentversion/run as well as the shortcuts). So, my solution is to call GetModuleFileName and parse the directory in it, that is: look for the last backslash character, pretty straightforward.
|
|
|
|
|
Ok, it works well !!
Thanks for your help.
|
|
|
|
|
Yes, as i know, GetCurrentDirectory function have this problem.
maybe you can save its path in registry.
|
|
|
|
|
suppose i define this c function as follow:
//my_c_func.h
extern "C" int a_c_func(void);
//my_c_func.c
#include "my_c_func.h"
int a_c_func(void)
{
//do sth...
return 0;
}
then i add this two file to a C++ program, call this c function, but the
C++ Builder 6 complains "Declaration terminate incorrectly". Why?
Can anyone give me a hint?
Thanks for your time!
|
|
|
|
|
What is 'extern' achieving here ? If it where me, I'd be whacking this in an anonymous namespace at the top of the cpp file where it's getting called.
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
In fact, i just have to use some functions from a lib written in C,so that why
i do it this way. i use extern "C", so i can use those functions' names directly(C++ do name-mangling, you know).
|
|
|
|
|
Ah - I see. But if they're in a lib, how do you have the c code, instead of just the header ? Or was the example flawed ?
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
Yes, you are right. i just have its header files. I want to call the functions directly. how can i achive this target?
thank you,Christian!
kirk
|
|
|
|