|
Smells like an stl issue.
You will get this type of message if you do something like this:
<br />
std::vector<long> vecLong;<br />
int n = vecLong.size();<br />
A lot of the stl classes returns a size_t numeric data type (instead of say, int, long etc).
Its not an error, but you should be aware of any overflow issues. If you are sure that your DWORD variable has enough range to accomodate the stl's size_t number, then just do a simple type cast.
<br />
std::vector<long> vecLong;<br />
int n = static_cast<int>(vecLong.size());<br />
I Dream of Absolute Zero
|
|
|
|
|
The compiler is telling you exactly what is wrong. Show the line of code in question.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
this is not an error. it is just a warning.
the compiler warns you about the fact that you copy some value of a particuliar type into a smaller type, hence the "possible loss of data".
what you can do to avoid this is :
- make the two types identical
- explicitely cast while assigning the value
- disable temporarily/totally the warning using the #pragma warning(disable:4267) statment...
|
|
|
|
|
toxcct wrote: - disable temporarily/totally the warning using the #pragma comment(disable:4267) statment...
I believe you meant #pragma warning(disable:4267) .
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: believe you meant #pragma warning(disable:4267).
yup, typo
|
|
|
|
|
Are you compiling as 64-bit by chance? I believe size_t is a 64-bit integer on 64-bit platforms whereas DWORD (which is just an unsigned long) is always 32-bits. Thus, if you try to implicitly cast a size_t to a DWORD, it will give you that warning. To get around it, either ignore it, use bitshift operations to get the lower 32-bits, or use static_cast to explicitly cast it to a DWORD.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
hi
i have funtion named change(long lngNo,unsigned char* pData);
where some times i send intger data,float data ,BOOL data as second parameter.How do i convert integer ,float ,BOOL to unsigned char*.
thanks in before
james
|
|
|
|
|
RockyJames wrote: How do i convert integer ,float ,BOOL to unsigned char*.
Use the address-of operator (&). For example:
int x;
change(5L, &x);
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
error C2664: : cannot convert parameter 2 from 'int *__w64 ' to 'unsigned char *'
|
|
|
|
|
You'll need to cast it, since change() is expecting an unsigned char * .
Why are you trying to make a one-size-fits-all function?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
can't you write several overloads of the function, which every func receive the right type ?
|
|
|
|
|
RockyJames wrote: i have funtion named change(long lngNo,unsigned char* pData);
where some times i send intger data,float data ,BOOL data as second parameter.How do i convert integer ,float ,BOOL to unsigned char*.
It is very bad practice to write a one-size-fits-all function. If you are trying to do something with the bytes (i.e. send them across a network using sockets), that is one thing, but if you are trying to decrease the number of methods you need to write for a given operation that doesn't involve direct byte transmissions, then this is the wrong approach.
A cleaner way of doing it would be to:
typedef unsigned long ulong;
typedef unsigned char byte;
void change(ulong size, byte* data)
{
}
template<class T> void change(const T& data)
{
change(sizeof(T), (byte*)&data);
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
The function is not written by me,it is one of the function in control.that`s the problem..so how can i send integer ,float ,BOOL in BYTE or unsinged char format.....?
|
|
|
|
|
If you have the ability to refactor the function, you should.
That said, if you are just looking to get something working with it, you can cast anything in memory to a char* (or anything else for that matter) by taking the address of it (note that it is not necessarily safe to do, but is possible):
struct MyStruct
{
};
MyStruct data;
change((char*)&data, sizeof(MyStruct));
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
In C++, how get the value and key in the IDictionary
Thanks.
|
|
|
|
|
Are you referring to the Keys and Values properties?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi I would like to start a powerpoint slideshow from C++ the way it is done by the shell. I think this is possible by using OLE automation but I could not find a good example to help me on the way. I prefere to use slideshow viewer only if this is possible. (don't use powerpoint) I am not using MFC.
Thanks: cool:
|
|
|
|
|
Remco Hoogenboezem wrote: Hi I would like to start a powerpoint slideshow from C++ the way it is done by the shell.
Then use ShellExecute() .
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Is it possible for me to link an SDI in my dialog based application? For example, when a button in the dialog is clicked, an SDI window comes up.
I've tried to 'File->Add->New Project' and added an SDI project into my current project but i have no idea how to link them up.
|
|
|
|
|
You mean start a new application (which is a SDI) ?
If yes, take a look at the FAQ[^]
|
|
|
|
|
No, not opening a different application but opening an SDI window from an SDI project which i included in my current Dialog based project
|
|
|
|
|
From your first post:
cv_k3n wrote: I've tried to 'File->Add->New Project' and added an SDI project into my current project but i have no idea how to link them up.
This will simply create a new project (so, a new executable) that will be added in your solution. They are unrelated and the only way to 'link' them is to have one execute the other one. So, this is not the solution.
I don't know how you could do this but you'll probably have to do everything manually (create a frame window, create the view and the document, ...). But I'm not sure if this will work.
|
|
|
|
|
cv_k3n wrote: No, not opening a different application but opening an SDI window from an SDI project which i included in my current Dialog based project
What you will want is to create an SDI application and display your dialog prior to displaying the SDI's mainframe (you'll be making some changes to the app's InitInstance method).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
how shall i start the dll hooking application
naresh
|
|
|
|