Author | Message | Time |
---|---|---|
Nabeshin | I am using VSC++.net2k3, and I was wondering how to use the DWORD type in C++. I am porting some code over from C# in order to make a Dynamic Link Library in C++, and I discovered that my complier does not reconsize the DWORD as an identifier, and it didn't reconize ZeroMemory or CopyMemory for some random reason. [code] #pragma once using namespace System; namespace CBnetHashing { ... } static void CBnetHashing::XSha1::HashData(System::Byte *inbuff, System::Int32 nLength, System::Byte *outbuff) { DWORD dhashbuff[128]; ZeroMemory(dhashbuff, 128*4); if (nLength > 64) throw new System::ArgumentException("Data cannot be more than 64 bytes"); CopyMemory(dhashbuff, inbuff, nLength); int i; DWORD a, b, c, d, e, f;... } [/code] (the dots represents code that I have yet to finish.) Basically, what I am trying to do is declair an array of the DWORD type (was used in C# code) into C++, ZeroMemory all of the addresses, and CopyMemory from inbuff to dhasbuff to a certain length. | February 24, 2005, 11:10 PM |
UserLoser. | [code] typedef unsigned long DWORD; [/code] or try including header files such as windows.h. | February 24, 2005, 11:15 PM |
Nabeshin | Thanks, I can't believe I forgot the header file. In the C# code, it refers to static functions, yet when I compile them, I get errors. [code] namespace CBnetHashing { public __gc class XSha1 { public: static void HashData(System::Byte *inbuff, System::Int32 nLength, System::Byte *outbuff); private: static System::UInt32 Rol(System::UInt32 n, int shift); }; [/code] How can I fix this (I don't remember hearing about static function)? | February 24, 2005, 11:37 PM |
UserLoser. | What errors? | February 24, 2005, 11:42 PM |
Nabeshin | error C2724: 'CBnetHashing::XSha1::Rol' : 'static' should not be used on member functions defined at file scope | February 25, 2005, 12:05 AM |
EpicOfTimeWasted | DWORD should actually be: [code]typedef unsigned int DWORD;[/code] This makes sure that your double word doesn't turn into a quad word when it's compiled for a 64 bit CPU. | February 25, 2005, 12:18 AM |
Kp | [quote author=EpicOfTimeWasted link=topic=10704.msg101457#msg101457 date=1109290728] DWORD should actually be: [code]typedef unsigned int DWORD;[/code] This makes sure that your double word doesn't turn into a quad word when it's compiled for a 64 bit CPU. [/quote] Technically, on a 64bit CPU, a doubleword should be 128 bits. Of course, it's rare you ever see a Windows programmer using the right definition of a machine word anyway. ;) | February 25, 2005, 12:30 AM |
Nabeshin | Thanks for the info but... Where do I put that? When I include it before the name, my compiler says that: error C2146: syntax error : missing ';' before identifier 'dhashbuff' So could you post an example of making an array of DWORD? From what I can make sence, it tries to make DWORD an interger, and wants to throw the rest of the declaration away. | February 25, 2005, 12:34 AM |
Kp | [code]DWORD dw[5] /* big enough for a SHA output */; DWORD *pdw = new DWORD[10] /* this line must be in a function, not at file scope */;[/code] | February 25, 2005, 12:44 AM |
Myndfyr | A couple thoughts.... You definitely didn't see a "DWORD" type in a C# library. The only "DWORD" type in a C# library would be System.UInt32 (System::UInt32), which is accessible through MC++, which brings me around to my next question, which is -- if you're using OTHER MC++ types like System::Byte, why aren't you using System::UInt32 instead of DWORD? Also, the C# "static" keyword means that you don't need to have an instance of an object to access that particular member. As I recall, in C++, you don't have to have an instance of an object, but you'll get an exception for trying to access a NULL pointer if the function you call uses the this pointer at all. I could be wrong on that, though. | February 25, 2005, 12:59 AM |
Nabeshin | Nah, my project partner thought that DWORD was the C++ equivelent of the C# uint, which it isn't (maybe I should have thought more into this before posting, oh well). Sure, I'll try and use System::UInt32 instead (this is what I originally planed to use, but Shout tried to convince me otherwise). | February 25, 2005, 2:04 AM |
R.a.B.B.i.T | [quote author=UserLoser link=topic=10704.msg101431#msg101431 date=1109286937]or try including header files such as windows.h.[/quote] | February 27, 2005, 3:30 AM |
shout | He is porting my BnetHashing.dll to C++, which is available in C# here. | February 27, 2005, 4:43 AM |
LordVader | This page, talks about general issues when trying to compile C# like code under C++ and general idea's on conversions & fixes. Most of the time it will just require (TYPE) cast infront of an instruction|function.. Where -> TYPE <- would be DWORD|INT etc.. or other 'type' of unit or structure known to the compiler. Example from the page I mentioned. In C this will work: [code] HBITMAP hbmOldBuffer = SelectObject(hdcBuffer, hbmBuffer); [/code] But in C++ requires a cast: [code] HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hdcBuffer, hbmBuffer); [/code] | March 1, 2005, 9:45 PM |