|
My reply is a little off topic: don’t use the “m_” Hungarian prefix on local variables! It’s meant to indicate class members.
Steve
|
|
|
|
|
its ok but whats the solution for me.?
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
|
WSAGetLastError() can help when socket APIs return an error.
I'm guessing you're either getting WSAEPROTOTYPE because you haven't specified a
protocol type or you're getting WSANOTINITIALISED because you haven't called
WSAStartup().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So, once again i must break away from c# and use c++. Not much of a probem really, until i get to something as simple as this.
So, i have a struct for a my colours, using floats for the RGB values because OpenGL really likes floats, meh. Anyway, i thought i'd add a constructor for it, and i come to the problem...
struct ColourRGB {
float Red;
float Green;
float Blue;
ColourRGB(float Red=0, float Green=0, float Blue=0);
};
All good. But, how can i make sure i set ColourRGB.Red to the parameter Red? Or must i just change the names of the parameters?
One day i'll read a book on c++ or something
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Try this:
struct ColourRGB
{
ColourRGB(float Red=0, float Green=0, float Blue=0)
: Red(Red)
, Green(Green)
, Blue(Blue)
{
}
float Red;
float Green;
float Blue;
};
Steve
|
|
|
|
|
Now i never knew you could do that with variables. Unless your just making it up
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
|
Article was very good! Thanks for the link!
Priya Sundar
|
|
|
|
|
Ever noticed how there seems to be two sorts of selection behaviours in comboboxes? One sort makes you click and release the button before you can select items in the drop down list. The other allows you to click and drag the mouse, and will select on the mouse button up.
The default ones that appear in my MFC programs seem to be the first type, where you have to click twice to select something. Is there a way to make them into a click and drag type selection?
|
|
|
|
|
following code snippet works in VC++ 6
file = fopen((LPCTSTR)CSTRING_VARIABLE,"wb+")
but in VC 2005 above code can not compile because of CString and casting problem.
how I can convert above code to be compatible with visual C++ 2005.
Regards
Gut Mikh
|
|
|
|
|
What's the actual error?
Second, do you really need the explicit cast? What is CSTRING_VARIABLE?
You should be able to use a CString without the cast there, unless there's
a conflict with char/wchar_t types.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
fopen function need one const char * as its first parameter.
in visual C++ 6 we can cast a CString variable to a char* by using (LPCTSTR) .
but this simple methodology does not work for visual C++ 2005.
Because we want to upgrade one project from VC6 to VC2005, thus it is neccessary to change it.
Now I want a simple code snippet which converts a CString variable to char* .
Regards
Gut Mikh.
|
|
|
|
|
You shouldn't need the cast. CString has a cast operator that does this for you.
I'm still wondering what the actual compiler error is.
Gut Mikh Tappe wrote: we can cast a CString variable to a char* by using (LPCTSTR)
That's not a valid cast. LPCTSTR is a constant pointer to a TCHAR.
TCHAR can be a char or a wchar_t, depending on if _UNICODE is defined.
Without knowing the error message, I'm guessing your build settings are for unicode,
in which case you should either change the project settings to not use unicode, use the
correct CStringT type, or use _tfopen() instead of fopen().
Regardless, you should NOT need the cast. Casts should be used only when absolutely necessary,
because they can hide errors, exactly as demonstrated here.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I do agree with Mark's comment. When you create a new project in Visual C++ 2005, probably you might have not noticed the "Use Unicode Libraries" in the Wizard.
While you are dealing with these it's better to use tchar functions. You can get those functions just by including #include <tchar.h>
Please post the error code if possible.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
i do agree with Sarath.
when you change the charset in the project property sheet from "Use Unicode Libraries" to "Use MBCS Libraries",the compile problem with CString will disappear at once.
|
|
|
|
|
Try:
LPCSTR
Instead of LPCTSTR
|
|
|
|
|
Drop the casts. Use code like this:
#include <tchar.h>
file = _tfopen(CSTRING_VARIABLE, _T("wb+"));
Steve
|
|
|
|
|
Any experienced people, would you please check my code fragments which is to collect all files of *.txt in the current directory where the present program resides. The following code is not working. It compiles, but did not pickup any files of *.txt in the directory.
I do not know why and where is the problem ? I try to store all the collected files into fileName[i].
Thanks alots for the guidance.
-------------------------------------------------
//
hFind = FindFirstFile("*.txt", &FindFileData);
fileName[0]=FindFileData.cFileName;
//
while (FindNextFile(hFind, &FindFileData) != 0)
{
i=+1;
fileName[i]=FindFileData.cFileName;
}
int nfile=i;
FindClose(hFind);
|
|
|
|
|
mrby123 wrote: i=+1;
Is that what you meant there? Or did you want
i += 1;
You probably want to increment i one more time after the while() loop to get
the proper file count.
You should also check and make sure FindFirstFile succeeds.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks You suggestion solve the problem. Thanks again.
|
|
|
|
|
can't you copy the file name with strcpy() or strncpy() instead of your own loop?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
mrby123 wrote: fileName[...]=FindFileData.cFileName;
Ouch. I didn't even look at that.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Maybe you want to change your code to this,do you want?
hFind = FindFirstFile(_T("*.txt"), &FindFileData);
int i=0;
do
{
fileName[i]=FindFileData.cFileName;
i++;
}while(FindNextFile(hFind, &FindFileData) != 0);
int nfile=i;
FindClose(hFind);
or like this
CStringArray str;
hFind = FindFirstFile(_T("*.txt"), &FindFileData);
do
{
str.Add(FindFileData.cFileName);
}while(FindNextFile(hFind, &FindFileData) != 0);
int nfile=str.GetCount();
FindClose(hFind);
|
|
|
|
|
Hello to all,
I never understand linker errors in visual studio,
I bring my class declaration, and the errors.
please advice me what to do.
header:
class Employee
{
public:
Employee(char* name, int hourFee, int hoursPerMonth, int overTime);
Employee(char* name, int hourFee, int hoursPerMonth);
Employee(char* name, int hourFee);
static int _minimumFee;
static int _maximumHours;
int getSalary();
void print();
int getHourFee();
void setHourFee(int hourFee);
int gethoursPerMonth();
void setHoursPerMonth(int hours);
private:
char* _name;
int _hourFee;
int _hoursPerMonth;
int _overTime;
};
implementation:
#include"Employee.h"
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
Employee::Employee(char* name, int hourFee, int hoursPerMonth, int overTime)
{
_name = strdup(name);
_hourFee = hourFee;
_hoursPerMonth = hoursPerMonth;
_overTime = overTime;
Employee::_minimumFee = 3600;
Employee::_maximumHours= 190;
}
Employee::Employee(char* name, int hourFee, int hoursPerMonth)
{
Employee::Employee(name, hourFee, hoursPerMonth, 0);
}
Employee::Employee(char* name, int hourFee)
{
Employee::Employee(name, hourFee, 160, 0);
}
int Employee::getSalary()
{
return (_hourFee * _hoursPerMonth) + (_overTime * (_hourFee * 2));
}
void Employee::print()
{
cout << "Employee, " << _name << " Salary = " << getSalary() << " hour Fee = " << _hourFee
<< " hours of work per month " << _hoursPerMonth << " over hours made = " << _overTime << endl;
}
void Employee::setHourFee(int hourFee)
{
if (hourFee < Employee::_minimumFee)
{
cout << "can't underpay a worker!!!" << endl;
return;
}
else
{
_hourFee = hourFee;
}
}
int Employee::getHourFee()
{
return _hourFee;
}
int Employee::gethoursPerMonth()
{
return _hoursPerMonth;
}
void Employee::setHoursPerMonth(int hours)
{
if(hours > Employee::_maximumHours)
{
_hoursPerMonth = 190;
_overTime = (hours - _hoursPerMonth);
}
else
{
_hoursPerMonth = hours;
}
}
ERRORS:
error LNK2019: unresolved external symbol "public: static int Employee::_maximumHours" (?_maximumHours@Employee@@2HA) referenced in function "public: __thiscall Employee::Employee(char *,int,int,int)" (??0Employee@@QAE@PADHHH@Z) Employee.obj
Error 3 error LNK2019: unresolved external symbol "public: static int Employee::_minimumFee" (?_minimumFee@Employee@@2HA) referenced in function "public: __thiscall Employee::Employee(char *,int,int,int)" (??0Employee@@QAE@PADHHH@Z) Employee.obj <br />
please help me.
|
|
|
|