|
|
Hi all,
got a question thats bugging me. I can not figure out this very simple compile error I am getting. Here is the error:
C:\Documents and Settings\mininet\My Documents\C++\9APR09\test.cpp In function `int main()':
28 C:\Documents and Settings\mininet\My Documents\C++\9APR09\test.cpp expected primary-expression before "GetLocalComputerName"
28 C:\Documents and Settings\mininet\My Documents\C++\9APR09\test.cpp expected `;' before "GetLocalComputerName"
I know its related to the string. but what is wrong with it? If you tell me whats wrong, dont just tell me. Please include a description of why the string is messed up. Thank you in advance! Code is as follows:
<code>// Project 01 by Rob
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
system("CLS");
string password;
string GetLocalComputerName;
cout << "password: ";
cin >> password;
if (password == "123"){
system("CLS"); // Cleares the screen
cout << "password accepted" << endl;}
else{
cout << "password incorrect" << endl;
goto exit;}
exit:
system("CLS");
system("TITLE Local Computer Name");
string GetLocalComputerName()
{
TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1];
string strRetVal;
DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1;
if(GetComputerName(chrComputerName,&dwBufferSize)) {
strRetVal = chrComputerName;
} else {
strRetVal = "";
}
return(strRetVal);
}
//std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\y' );
return 0;
}
V/R
Rob
|
|
|
|
|
rbwest86 wrote: string GetLocalComputerName()
What is this?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
it is a string, i could have called it anything. But I kept it familiar with the function. All I am trying to do is retrieve the local computer name.
|
|
|
|
|
rbwest86 wrote: it is a string...
No, it's the beginning of a nested function, which is not allowed.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hello Rob,
You've defined GetLocalComputerName() inside main() . Nested function definition is illegal. So move GetLocalComputerName() outside to resolve the error.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
First off thank you very much. I read into the embeded function and your right, it will not work.
I do however feel there is something missing. I relocated the entire section related to retrieving the local computer name, to outside int main().
I think there needs to be
#include <fstream>
and have string GetLocalComputerName; cin >> or output somehow. Because the program compiles, yet it dosent seem as if it is doing anything. After I type in the password, it should jump to the next sequential portion of the program, and retrieve the username. It does nothing but stare back at me. I feel as if I am missing something, can someone point me in the right direction? I do a lot of reading but the reading needs to be put into perspective. Thank you very much in advance.
V/R
Rob
|
|
|
|
|
Hi Rob,
You should call GetLocalComputerName() function and print it. For instance, see the corrected code snippet.
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
string GetLocalComputerName()
{
TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1];
string strRetVal;
DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1;
if(GetComputerName(chrComputerName,&dwBufferSize)) {
strRetVal = chrComputerName;
} else {
strRetVal = "";
}
return(strRetVal);
}
int main()
{
system("CLS");
string password;
cout << "password: ";
cin >> password;
if (password == "123"){
system("CLS");
cout << "password accepted" << endl;}
else{
cout << "password incorrect" << endl;
goto exit;}
exit:
system("CLS");
system("TITLE Local Computer Name");
cout << GetLocalComputerName();
return 0;
}
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
I'm looking at using some of the new stuff that comes from the MFC Service Pack in our current application (possible release date for this is late this year, so it's not urgent)
We have at least one resource ID conflict between our resources and the new resources in the Service Pack.
for example :
our code:
#define IDS_MESSAGE_FORMAT 17018
MFC code:
#define IDS_AFXBARRES_ADD_REMOVE_BTNS 17018
What's the best strategy to clean up resources to prevent/limit/remove conflicts ?
I have used ResOrganiser[^] and it works ok, but looking for preentive solutions.
Thanks.
Max.
This signature was proudly tested on animals.
|
|
|
|
|
The code I'm writing is designed to read into a Smart Card Reader. However, I've having a most difficult time trying to just setup the connection and get the filename so I can use CreateFile.
I've looked at the MSDN Library and done countless searches on the topic and have seen various things. Some people allocate the SP_DEVICE_INTERFACE_DETAIL_DATA struct, and claim it works, and some don't and they also claim it works (Both of which do not work for me).
The current way my code is set up right now pulls the required size, but when it goes to fill in the struct, the program freezes. Quite frustrating, really.
So here's my question: What must I do to the struct prior to attempting to fill it in with SetupDiGetDeviceInterfaceDetail in order to pull up *->DevicePath ??
Here's the code:
....
//declarations
int n=0, result;
char af[80]="";
bool found=FALSE;
GUID SCRGuId;
DWORD requiredsize=0;
HDEVINFO hDevInfo=NULL;
SP_DEVICE_INTERFACE_DATA DeviceInfoData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DevDetailInfoData;
....
do
{
if(SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &SCRGuId, n, &DeviceInfoData))
{
found = TRUE; requiredsize = 0;
SetupDiGetDeviceInterfaceDetail(hDevInfo,&DeviceInfoData,NULL,0,&requiredsize,NULL);
sprintf(af, "reqsize: %d", requiredsize);
SendDlgItemMessage(hWnd, IDC_ACTIONLIST, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)af);
if(requiredsize != 0)
{
//this is the problem code...can anybody help me here?
DevDetailInfoData->cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SetupDiGetDeviceInterfaceDetail(hDevInfo,&DeviceInfoData, DevDetailInfoData,requiredsize,0,NULL);
sprintf(af, "device path %s", DevDetailInfoData->;DevicePath);
SendDlgItemMessage(hWnd, IDC_ACTIONLIST, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)af);
}else{
....
|
|
|
|
|
I use this approach when querying audio devices using the ANSI API's ...
<pre>
// Get details for the device registered in this class
DWORD size = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + MAX_PATH * sizeof(WCHAR);
// use vector so it will clean up afterwards
std::vector<BYTE> buffer(size,0);
// set up the pointer
SP_DEVICE_INTERFACE_DETAIL_DATA* pDevInterfaceDetails =
reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>(&buffer[0]);
// let SetupDi know how big a buffer we have ...
pDevInterfaceDetails->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
// get the device path ...
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo,&DID,pDevInterfaceDetails,size,NULL,&DevInfoData))
{
continue;
}
Apologies for CP formatting ...
Jerry
|
|
|
|
|
Thank you thank you thank you! Jerry, despite the CP formatting, you just helped me solve my problem! Thanks!
|
|
|
|
|
"Error spawning 'cmd.exe'"
I always got this error when I build my project (using VS2005).
Please help me to solve this problem.
|
|
|
|
|
Max++ wrote: Please help me to solve this problem.
Start here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi, I've set breakpoints in my application. Last night my breakpoints were being hit ok. This morning none of the breakpoints that are set are being hit. So I deleted the project's NCB file. Spurious results at best. I deleted the NCB file again, restarted, cleaned project then rebuilt and my breakpoints are being hit again. Yeah.
However, if I set new breakpoints those breakpoints are missed/skipped.
WTH?
Signed,
Perplexium ad infinitum
|
|
|
|
|
Are you sure you are running a debug build?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
In VC6 at least, breakpoints are stored in the .opt file. .ncb is a pest that gets corrupted regularly by intellisense!
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Didn't know the OPT was used for that! Thank you!! :P
I was able to get it to work - after I deleted all my breakpoints. I'll now next what to do ahead of schedule.
Cheers!!
|
|
|
|
|
how to control Stepper Motor Control drive through serial Port member
hi, nice to meet you good people down there. i am a novice programmer, i will be very grateful if you could help me please
how can i control Stepper Motor Control drive through serial Port instead of parallel port by using language such as c/c++
My kindest regards
Sahih
|
|
|
|
|
sahih wrote: how can i control Stepper Motor Control drive through serial Port instead of parallel port by using language such as c/c++
All depends how the serial port interfaces with the stepper motor compared to the parallel port (do PCs still come with those?).
Here's a good place to start with serial port programming[^], anyway.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Does your stepper motor driver support serial port communication?
If the answer is yes then check out the relative documentation to understand what your application should do. PC side serial communication is a well-trodden path and you will find tons of tutorial, samples, etc...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am drawing using OpenGL and GDI on top of a picture which were drawn before in CView::OnDraw function.
First 2-3 seconds it draws sucessfully, and then cursor of mouse become "clock"( meanth beasy )
and on the screen is nothing drowning. Also the same problem apear during drawing of progress bar, after some time
it become grey and squares of progress bar isn't drawn.
|
|
|
|
|
I don't know what "meanth beasy" means.
Gastello wrote: on the screen is nothing drowning
Is stuff supposed to be drowning?
Gastello wrote: it become grey and squares of progress bar isn't drawn.
Well you didn't ask any questions but given what you did say it sounds like you should consider getting some good material (books or internet tutorials) designed to teach beginners how Windows Device Contexts and Drawing/Painting works.
good luck
|
|
|
|
|
led mike wrote: I don't know what "meanth beasy" means.
My gibberish translator suggests 'means busy'? I've never seen a keyboard with a lisp before now, though...well, apart from this one[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Sory for my English
"means beasy" means "sand-glass" cursor appear
I am not amateur, and I don't have time to learn in detail how Windows Device Contexts works. I did not put any question because I explained the problem, and usualy peoble understand it that I need help to solve the problem.
|
|
|
|