【问题标题】:Compile Error C3861 Visual Studio 2010编译错误 C3861 Visual Studio 2010
【发布时间】:2012-11-15 01:37:27
【问题描述】:

我遇到了两个错误,我这辈子都想不通... 在过去的几个小时里,我在谷歌上研究了它。我现在在哪里。 这是我得到的编译错误。

    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;
}

【问题讨论】:

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


    【解决方案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)。

    【讨论】:

    • 我的 typedefs.h 包含文件在 stdafx.h 中?我应该只将 extern 放在我的 dllmain.cpp 中吗?
    • @Pepsi_1 实际上,我会将 extern 放在 typedefs.h 头文件的底部,就在 #endif 结束你的守卫岗位内。我正要在此处更新答案以表明这是另一种选择。
    猜你喜欢
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多