|
Razanust wrote: Any clue to the solution???
Well, something like this comes to mind:
std::ifstream fin;
std::vector<Record> records;
fin.open("c:\\Records.txt");
std::copy(std::istream_iterator<Record>(fin), std::istream_iterator<Record>(), std::back_inserter(records));
fin.close(); Hint: you'll need to create the Record class.
"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, how to set an image as a background for dialog box or form in vc++?
Thanks in advance..
|
|
|
|
|
|
I wonder why your posting was down voted.
I have compensated it.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
void CClass::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPaintDC dcc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP1);
//IDB_BITMAP1 is the image ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,
bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
}
|
|
|
|
|
Hi,
I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:
1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)
In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008
Thanks in advance
#pragma once
#include <string>
#include <vector>
class CStringParser
{
public:
CStringParser::CStringParser();
CStringParser::~CStringParser();
std::vector<CString> CStringParser::ParseString(CString s, CString c);
};
#pragma once
#include "StringParser.h"
#include <string>
#include <vector>
CStringParser::CStringParser()
{
}
CStringParser::~CStringParser()
{
}
std::vector<CString> CStringParser::ParseString(CString s, CString c )
{
............
}
#pragma once
#include "StringParser.h"
class Test
{
public:
Test(void);
~Test(void);
private:
CStringParser sp;
};
|
|
|
|
|
Have you added StringParser.cpp to your project?
|
|
|
|
|
Member 4705538 wrote: Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files.
What do you mean by previously include .cpp files?
Do you mean #include or include in the project?
You're most likely not including StringParser.cpp as part of the project.
If you don't, this file will not be compiled into an obj file.
The linker, when creating the executable will search for the functions(symbols) in the obj files.
And since StringParser.obj hasn't been created, it cannot find the constructor and destructor function definitions and so the errors.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the replies, and yes i haven't included the cpp file into my project, do i just simply include it into any of my files that use the CStringParser or shall i include it in settings or stdafx.h?
|
|
|
|
|
Right click on the project name is solutions explorer and select add existing item.
Select StringParser.cpp
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the quick reply again, i did that but then i got the following errors
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(2) : warning C4627: '#include <string>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(3) : warning C4627: '#include <vector>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(4) : warning C4627: '#include "CStringParser.h"': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(48) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file, but i was wondering if theres a way of only including the header files or something, but i guess ill stick to my way.
Thanks for the replies 
|
|
|
|
|
Member 4705538 wrote: I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file
This is not the right way.
Look at the error message.
That is what you need to do.
Just ensure that #include <stdafx.h> is the first line in all .cpp files.
I guess you're missing that in StringParser.cpp.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Try adding file directory of CStringParser in Additional Include directories option.
It's not enough to be the best, when you have capability to be great....
|
|
|
|
|
Pavan_Putra wrote: Try adding file directory of CStringParser in Additional Include directories option
No, this won't change anything: he has linker errors, not compilation errors. Thus the include are fine.
|
|
|
|
|
Member 4705538 wrote: In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008
In that case, you either need to a) make a library (static or dynamic, static's probably easier) out of your .cpp file and point your including code at that, or b) wedge all the code from the .cpp file into the .h file (probably not a great idea - don't forget the 'inline' specifiers if you do do that).
But...what do you actually mean by 'do it properly using only header files'?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
By properly, i mean when i look at pieces of code, i always only see a something.h, never a something.cpp, in my own code i always had to add the supplier.h to the client.h and the supplier.cpp to the client.cpp, but was wondering if there is a better way of doing it?
|
|
|
|
|
Member 4705538 wrote: By properly, i mean when i look at pieces of code, i always only see a something.h, never a something.cpp, in my own code i always had to add the supplier.h to the client.h and the supplier.cpp to the client.cpp, but was wondering if there is a better way of doing it?
Short answer - yes, there are better ways of doing it.
Longer answer - there are two approaches you could consider. Firstly, as I suggested earlier, make a library (static or dynamic, static's probably easier)[^] out of the supplier.cpp file and get the code that uses it to link against that library. Secondly, you could just add the supplier.cpp file to the Visual Studio project that contains client.cpp. That will automatically include the compiled object files of supplier.cpp and client.cpp in the final executable, which should mean it links and build successfully.
HTH!!!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
lack of impleation file
Like C++ more
|
|
|
|
|
I want to read the records of some students such as their age, names, marks in tests etc. from a text file.
Can these records be saved directly from a file to a structure?
(I mean we are not taking any input from the user.)
Any other way to do this job?
|
|
|
|
|
I think the code will help in your problem if the file is made by filling the same structure.
Try this
int nNumberOfBytes = 0;
bool bRead = ReadFile(
hMyFile,
(LPVOID)MyStruct,
sizeof(MyStruct),
&nNumberOfBytes,
NULL);
Harsh
|
|
|
|
|
Razanust wrote: Can these records be saved directly from a file to a structure?
Yes, of course.
Razanust wrote: Any other way to do this job?
There are other ways (such as reading from a database...).
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]
|
|
|
|
|
Hello, I'm David. Recently I've been working on a project... A robot that can be controlled locally by a Xbox360 controller, and eventually will be controlled remotely the same way. To control the motors on the robot I have to link with a DLL, and so far it works for a bit, but soon after starting the app it is closed for Access Violations. This issue deffinately envolves the definitions and pointers and such to the DLL... What is going wrong, and how can i prevent it from happening?
Thanks, David Kirby
/*-----------------------------------------------------------------------------------------------*/
#include "CXBOXController.h"
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <cstdlib>
typedef bool (*Type_InitMotoBee)();
typedef bool (*Type_SetMotors)(int on1, int speed1, int on2, int speed2, int on3, int speed3, int on4, int speed4, int servo);
typedef void (*Type_Digital_IO)(int *inputs, int outputs);
using namespace std;
HINSTANCE MHtbDLL=LoadLibrary(_T("mtb.dll"));
CXBOXController* Player1;
int main(int argc, char* argv[])
{
Player1 = new CXBOXController(1);
system("Color 02");
system("title LANbot Host - Local Motor Control Trial");
cout << " __ _ __ _ _ |\n"
<< " / / /_\\ /\\ \\ \\ |__ ___ | |_ |\n"
<< " / / //_\\\\ / \\/ / '_ \\ / _ \\| __| |\n"
<< " / /___/ _ \\/ /\\ /| |_) | (_) | |_ |\n"
<< " \\____/\\_/ \\_/\\_\\ \\/ |_.__/ \\___/ \\__| 2009|\n"
<< "--------------------------------------------\n\n";
//End Title Bar
if(MHtbDLL != NULL){cout << "\tMtb.dll Loaded Successfuly...";}
if(MHtbDLL == NULL)
{
cout << "\tMtb.dll did NOT load Successfuly!\n"
<< "\tCheck to see that Mtb.dll is in the same\n"
<< "\tdirectory as this executable.\n\n"
<< "\tPress [Enter] to Continue...";
cin.get();
}
Sleep(1000); system("cls");
int speed = 1;
int gR = 128;
int button=0;
Type_InitMotoBee InitMotoBee;
Type_SetMotors SetMotors;
Type_Digital_IO Digital_IO;
InitMotoBee = (Type_InitMotoBee)GetProcAddress(MHtbDLL, "InitMotoBee");
SetMotors = (Type_SetMotors)GetProcAddress(MHtbDLL, "SetMotors");
Digital_IO = (Type_Digital_IO)GetProcAddress(MHtbDLL, "Digital_IO");
InitMotoBee();
while(true)
{
if(Player1->IsConnected())
{
//Set both motors Foward
if(Player1->GetState().Gamepad.sThumbLY > 5001
&& Player1->GetState().Gamepad.sThumbLX > -4999
&& Player1->GetState().Gamepad.sThumbLX < 4999
&& button==0)
{
SetMotors(1,gR,0,0,1,gR,0,0,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLY > 5001
&& Player1->GetState().Gamepad.sThumbLX > -4999
&& Player1->GetState().Gamepad.sThumbLX < 4999
&& button==1)
{
cout << "\n\n\t\t\tFOWARD\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Set Right motor foward, turn Left
if(Player1->GetState().Gamepad.sThumbLY > 5001
&& Player1->GetState().Gamepad.sThumbLX < -4999
&& button==0)
{
SetMotors(1,gR,0,0,0,0,0,0,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLY > 5001
&& Player1->GetState().Gamepad.sThumbLX < -4999
&& button==1)
{
cout << "\n\n\t\t\tFOWARD, LEFT TURN\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Set Left Motor Foward, turn Right.
if(Player1->GetState().Gamepad.sThumbLY > 5001
&& Player1->GetState().Gamepad.sThumbLX > 4999
&& button==0)
{
SetMotors(0,0,0,0,1,gR,0,0,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLY > 5001
&& Player1->GetState().Gamepad.sThumbLX > 4999
&& button==1)
{
cout << "\n\n\t\t\tFOWARD, TURN RIGHT\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Set both motors in reverse
if(Player1->GetState().Gamepad.sThumbLY < -5001
&& Player1->GetState().Gamepad.sThumbLX > -4999
&& Player1->GetState().Gamepad.sThumbLX < 4999
&& button==0)
{
SetMotors(0,0,1,128,0,0,1,128,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLY < -5001
&& Player1->GetState().Gamepad.sThumbLX > -4999
&& Player1->GetState().Gamepad.sThumbLX < 4999
&& button==1)
{
cout << "\n\n\t\t\tREVERSE\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Reverse Right motor
if(Player1->GetState().Gamepad.sThumbLY < -5001
&& Player1->GetState().Gamepad.sThumbLX < -4999
&& button==0)
{
SetMotors(0,0,1,128,0,0,0,0,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLY < -5001
&& Player1->GetState().Gamepad.sThumbLX < -4999
&& button==1)
{
cout << "\n\n\t\t\tREVERSE, TURN LEFT\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Reverse Left Motor
if(Player1->GetState().Gamepad.sThumbLY < -5001
&& Player1->GetState().Gamepad.sThumbLX > 4999
&& button==0)
{
SetMotors(0,0,0,0,0,0,1,128,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLY < -5001
&& Player1->GetState().Gamepad.sThumbLX > 4999
&& button==1)
{
cout << "\n\n\t\t\tREVERSE, TURN RIGHT\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Spin Right
if(Player1->GetState().Gamepad.sThumbLX > 5001
&& Player1->GetState().Gamepad.sThumbLY < 4999
&& Player1->GetState().Gamepad.sThumbLY > -4999
&& button==0)
{
SetMotors(0,0,1,gR,1,gR,0,0,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLX > 5001
&& Player1->GetState().Gamepad.sThumbLY < 4999
&& Player1->GetState().Gamepad.sThumbLY > -4999
&& button==1)
{
cout << "\n\n\t\t\tSPIN RIGHT\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Spin Left
if(Player1->GetState().Gamepad.sThumbLX < -5001
&& Player1->GetState().Gamepad.sThumbLY < 4999
&& Player1->GetState().Gamepad.sThumbLY > -4999
&& button==0)
{
SetMotors(1,gR,0,0,0,0,1,gR,0);
button=1;
while(Player1->GetState().Gamepad.sThumbLX < -5001
&& Player1->GetState().Gamepad.sThumbLY < 4999
&& Player1->GetState().Gamepad.sThumbLY > -4999
&& button==1)
{
cout << "\n\n\t\t\tSPIN LEFT\n";
system("cls");
}
button=0;
SetMotors(0,0,0,0,0,0,0,0,0);
}
//Angle Servo up
if(Player1->GetState().Gamepad.sThumbRY > 5000)
{
cout << "\n\n\t\t\tCAMERA UP\n";
system("cls");
}
//Angle Servo Down
if(Player1->GetState().Gamepad.sThumbRY < -5000)
{
cout << "\n\n\t\t\tCAMERA DOWN\n";
system("cls");
}
//Stop Motors
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)
{
SetMotors(0,0,0,0,0,0,0,0,0);
cout << "STOPPED";
system("cls");
}
//Gear One
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
{
speed=1; gR=128;
while(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
{
cout << "\n\n\t\t\tShifting. You are now in gear " << speed << ".\n";
system("cls");
}
}
//Gear Two
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B)
{
speed=2; gR=189;
while(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B)
{
cout << "\n\n\t\t\tShifting. You are now in gear " << speed << ".\n";
system("cls");
}
}
//Gear Three
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_Y)
{
speed=3; gR=250;
while(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_Y)
{
cout << "\n\n\t\t\tShifting. You are now in gear " << speed << ".\n";
system("cls");
}
}
/*if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_START)
{
SetMotors(0,0,0,0,0,0,0,0,0);
int brake=1;
cout << "BRAKE";
while(brake==1)
{
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_START)
{
brake++;
}
}
system("cls");
}*/
//Exit Loop (break;)
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
{
system("cls");
cout << "\n\n\tUnloading library...\n";
FreeLibrary(MHtbDLL);
Sleep(1000);
if(MHtbDLL!=NULL){cout << "\n\n\tMtb.dll Did NOT Unload Successfuly!";}
if(MHtbDLL==NULL){cout << "\n\n\tMtb.dll Unloaded Successfuly...";}
Sleep(1000);
break;
}
}
//Controller Not present
else
{
cout << "\n\t\t\tWhere is the controller? o.0\n";
cout << "\t\t\t Press [ENTER] To Exit.";
cin.get();
system("cls");
cout << "\n\n\tUnloading library...\n";
FreeLibrary(MHtbDLL);
Sleep(1000);
if(MHtbDLL!=NULL){cout << "\n\n\tMtb.dll Did NOT Unload Successfuly!";}
if(MHtbDLL==NULL){cout << "\n\n\tMtb.dll Unloaded Successfuly...";}
Sleep(1000);
break;
}
}
delete(Player1);
return( 0 );
}
<code></code><code></code><pre></pre>
|
|
|
|
|
This would be too much work for somebody trying to help you.
It is for me. So you should consider drilling this down to a more specific area.
These are some comments from me.
Don't use new unless you really need it.
You are using too many system function calls.
The code is not properly indented.
You are not checking return values for errors.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the reply. Im getting and error with these...
typedef bool (*Type_InitMotoBee)();
typedef bool (*Type_SetMotors)(int on1, int speed1, int on2, int speed2, int on3, int speed3, int on4, int speed4, int servo);
typedef void (*Type_Digital_IO)(int *inputs, int outputs);
HINSTANCE MHtbDLL=LoadLibrary(_T("mtb.dll"));
Type_InitMotoBee InitMotoBee;
Type_SetMotors SetMotors;
Type_Digital_IO Digital_IO;
InitMotoBee = (Type_InitMotoBee)GetProcAddress(MHtbDLL, "InitMotoBee");
SetMotors = (Type_SetMotors)GetProcAddress(MHtbDLL, "SetMotors");
Digital_IO = (Type_Digital_IO)GetProcAddress(MHtbDLL, "Digital_IO");
This is where the program calls the DLL, makes pointers, etc.
After I use SetMotors(); so many times, the program is terminated for an access violation... I cant figure it out. If i comment out everything that envolves the DLL, my program works perfectly.
Thanks,
David
|
|
|
|
|
Check for any uninitialized or dangling pointers inside SetMotors.
Check if there is any difference in behavior in Debug and Release builds.
Also set the warning level to the highest level in the project properties.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|