开发者

Issues when moving code from one class into a new class?

I had some decryption code (using wincrypt.h) that lived within my FileReader.cpp class. I am trying to segregate the code and push this decryption method into a MyCrypt.cpp class. However, upon moving it I'm stuck with a bunch of errors that I wasn't facing before. For every wincrypt.h or windows.h specific command, I am recieving "identifier not found" or "undeclared identifier".

What gives!

More details..

Sample errors:

error C2065: 'HCRYPTPROV' : undeclared identifier

error C3861: 'CryptDecrypt': identifier not found

I am including windows.h and wincrypt.h, just as I was in FileReader.cpp.

#include "MyCrypt.h"
#include <windows.h>
#include <wincrypt.h>

MyCrypt.h is defined as:

#pragma once

class MyCrypt
{
public:
    static char *DecryptMyFile(char *input, char *password, int size, int originalSize) ;

private:
    static const DWORD KEY_LENGTH = 128;
}

If I rearrange my include files, I get the following errors instead:

error C2628: 'MyCrypt' followed by 'char' is illegal (did you forget a ';'?) error C2556: 'MyCrypt *MyCrypt::DecryptMyFile(char *,char *,int,int)' : overloaded function differs only by return type from 'char *MyCrypt::DecryptMyFile(char *,char *,int,int)

开发者_StackOverflowBut nowhere in my code does it use this redefinition it speaks of..


Check MyCrypt.h and make sure there's a ; after the closing brace. I've seen some fairly strange error messages when I've missed that. It's missing in the sample you posted.


Did you forget the semicolon after your class declaration?


Sounds like the code you moved out of FileReader.cpp was either referencing member variables of that class which don't exist in MyCrypt.cpp or methods that were #included in FileReader.cpp that weren't included in MyCrypt.cpp.


Sounds like you are now missing some #include's in the new MyCrypt.cpp file, such as windows.h and wincrypt.h, but we need the actual errors to specifically helpful.


Some ideas:

  • are you calling methods without referencing the object first (since they were in the old class and now moved, maybe you forgot to call them through a pointer in the new class?)
  • you could try shifting the order of the include statements.
  • are you using precompiled headers? You could try without to see if that fixes the problem.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜