编译错误C3861 Visual Studio 2010

时间:2012-11-15 01:37:28

标签: c++ c visual-studio-2010 dll compiler-errors

我遇到两个错误,无法解决我的生活...... 我在过去的几个小时里一直在google上研究它。我现在到了哪里。 以下是我得到的编译错误。

    2   IntelliSense: identifier "RegisterShader" is undefined  c:\users\administrator\documents\visual studio 2010\projects\test\dllmain.cpp   18  20  

Error   1   error C3861: 'RegisterShader': identifier not found c:\users\administrator\documents\visual studio 2010\projects\test\dllmain.cpp   50  1   

// stdafx.h

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

// TODO: reference additional headers your program requires here
#include <detours.h>
#include "typedefs.h"

// stdafx.cpp

// stdafx.cpp : source file that includes just the standard includes
// blopsII.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

// typedefs.h

#ifndef TYPEDEFS_H
#define TYPEDEFS_H

#define OFF_REGISTERSHADER 0x00715690

typedef float  vec_t;
typedef vec_t  vec2_t[2];
typedef vec_t  vec3_t[3];
typedef vec_t  vec4_t[4];
typedef int    qhandle_t;

typedef int ( * tRegisterShader )( char* szName, int unk );

#endif

// typedefs.cpp

#include "stdafx.h"

tRegisterShader RegisterShader = ( tRegisterShader )OFF_REGISTERSHADER;

// dllmain.cpp

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

//#include "typedefs.h"

DWORD dwHook = 0x6ADC30;

void callback()
{

    qhandle_t white = RegisterShader("white", 3);
}


int __cdecl hkRender()
{
    _asm pushad;
    callback();
    _asm popad;
}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:



    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

1 个答案:

答案 0 :(得分:1)

有几种方法可以做到这一点:

<强> dllmain.cpp

#include "stdafx.h"
#include "typedefs.h"

extern tRegisterShader RegisterShader;

剩下的就像你已经拥有它一样。


或者,您可以通过将extern放在typedefs.h的底部来“发布”typedefs.cpp中定义的变量:

<强> typedefs.h

#ifndef TYPEDEFS_H
#define TYPEDEFS_H

#define OFF_REGISTERSHADER 0x00715690

typedef float  vec_t;
typedef vec_t  vec2_t[2];
typedef vec_t  vec3_t[3];
typedef vec_t  vec4_t[4];
typedef int    qhandle_t;

typedef int ( * tRegisterShader )( char* szName, int unk );

extern tRegisterShader RegisterShader;

#endif

后一种方法在发布头文件中定义的类型的全局变量时很常见,其中变量在匹配的.cpp文件中定义。在标题中将其声明为extern有效地将其暴露给任何人,包括标题(包括你的dllmain.cpp)。