c++ - 编译错误 C3861 Visual Studio 2010

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

我遇到了两个错误,我这辈子都弄不明白... 在过去的几个小时里,我已经在谷歌上对其进行了研究。我现在到了哪里。 这是我遇到的编译错误。

    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

//类型定义.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

//类型定义.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;
}

最佳答案

实现此目的的几种方法:

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 文件中定义。在 header 中将其声明为 extern 有效地将其暴露给包括 header (包括您的 dllmain.cpp)在内的任何人。

关于c++ - 编译错误 C3861 Visual Studio 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390332/

相关文章:

c++ - 使用 vector<char> 作为输入缓冲区比 char 数组有什么优势?

c++ - 玩家捡起元素后,元素不会被删除

c++ - 类(class)成员重新排序

c - ncurses color_content() 给了我错误的值

c - 哪个内核函数调用了用户空间中实现的 timer_settime() 和定时器处理程序?

visual-studio-2010 - 是否可以在 Visual Studio 中重命名项目,使其文件夹名称也重命名?

c++ - 尝试使用 strcpy 时看到应用程序崩溃

c - 在链表上实现归并排序

visual-studio-2010 - Azure VM 大小可以通过服务配置来配置吗?

c# - Visual Studio 2010 : Add new class file that inherits from existing class?