这是C4055警告消息.
'conversion':从数据指针'type1'到函数指针'type2'
数据指针被转换(可能不正确)到函数指针.
这是/ Za下的1级警告和/ Ze下的4级警告.
我们如何解决这个警告?(以正确的方式,不是一招)
编辑:
这是一个代码片段有警告.
typedef NTSTATUS (*t_ObRegisterCallbacks)
(
IN POB_CALLBACK_REGISTRATION CallBackRegistration,
OUT PVOID *RegistrationHandle
);
t_ObRegisterCallbacks g_ObRegisterCallbacks = NULL;
void foo()
{
g_ObRegisterCallbacks = (t_ObRegisterCallbacks)MmGetSystemRoutineAddress(®Name); //C4055
}
//warning C4055: 'type cast' : from data pointer 'PVOID' to function pointer 't_ObRegisterCallbacks'
Run Code Online (Sandbox Code Playgroud) 在本文档中, http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#paths
为了使 Windows 应用程序可以访问这些设备对象,设备驱动程序在 Win32 命名空间“Global??”中创建了一个符号链接(symlink),指向它们各自的设备对象。例如“Global??”下的COM0 和COM1 子目录只是指向 Serial0 和 Serial1 的符号链接,“C:”是指向 HarddiskVolume1 的符号链接,“Physicaldrive0”是指向 DR0 的符号链接,依此类推。如果没有符号链接,使用 Win32 命名空间约定的任何 Windows 应用程序将无法使用指定的设备“Xxx”,如前所述。但是,可以使用任何支持格式为“\Device\Xxx”的 NT 命名空间绝对路径的 API 打开该设备的句柄。
什么是 API?请让我知道一些这样的功能。
例如,我们可以在GLOBAL??命名空间中放置一个设备:
GLOBAL??\
COM227
Run Code Online (Sandbox Code Playgroud)
我们可以使用CreateFile以下方法成功打开此设备:
//Note: we have to prefix it with \\.\ in order to tell CreateFile that
//we want to open something from the Global device namespace.
//Otherwise it will try to open a file
HANDLE hdev = CreateFile("\\.\COM227", GENERIC_READ, 0, null, OPEN_EXISTING, 0, 0);
if (hdev …Run Code Online (Sandbox Code Playgroud) 据我所知,只有caller-clean-stack约定可以使用变量参数.
顺便说一句,WinApi StringCchPrintfW就是这样声明的.(我删除了SAL)
__inline HRESULT __stdcall StringCchPrintfW
(
STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,...
);
stdcall可以有变量参数吗?
windows winapi variadic-functions calling-convention stdcall
// common.h
// This is foo function. It has a body.
__inline void foo() { /* something */ }
// a.cpp
#include "common.h" // for foo function
// Call foo
// b.cpp
#include "common.h" // for foo function
// Call foo
Run Code Online (Sandbox Code Playgroud)
我想在我为发布版本构建时内联foo函数.我不想内联函数进行Debug构建.
我试过了,但链接器错误让我烦恼.
在这种情况下,foo函数的主体在common.h头文件中定义.
所以,如果我这样做
//common.h
#if !defined(_DEBUG)
__inline
#endif
void foo() { /* something */ }
Run Code Online (Sandbox Code Playgroud)
它将在DEBUG构建中遇到链接错误.因为两个模块试图包含common.h.
我不知道要解决它.
可能吗?

安装paint.net,我找到一个字符串创建系统还原点...
我想它正在为卷影服务创建一个还原点. - 不是吗?我不确定.
如果我是对的,我该如何在我的应用程序中执行此操作?
如果有合适的Apis,请告诉我.
可能重复:
C++标题顺序
// Here is module This.cpp
#include <boost/regex.hpp>
#include <iostream>
#include <math.h>
#include "mystring_written_by_c.h"
#include "mystring_written_by_cpp.h"
#include <list>
#include <string>
#include <stdio.h>
#include "stdafx.h" // for precomp
#include <tchar.h>
#include "This.h"
#include <Windows.h>
#include <Winsock2.h>
Run Code Online (Sandbox Code Playgroud)
它们现在按字母顺序排列.
我找到了订购它们的最佳做法.(有一个很好的配方吗?)
你将如何订购这些头文件?为什么?
CRITICAL_SECTION锁定(进入)和解锁(离开)是有效的,因为CS测试是在用户空间中执行的,而不会进行互斥锁所做的内核系统调用.解锁完全在用户空间中执行,而ReleaseMutex需要系统调用.
我刚读完这本书中的这些句子.
内核系统调用的意思是什么?你能给我这个功能的名字吗?
我是英国新手.我这样解释他们.
另一个问题.
当我们打开一个删除挂起的文件时,即使Windows子系统具有ERROR_DELETE_PENDING状态,它们也会返回ERROR_ACCESS_DENIED。
HANDLE h = CreateFile(L"C:\\test.txt",
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, 0, CREATE_ALWAYS, 0, 0);
// Succeed
BOOL fOk = DeleteFile(L"C:\\test.txt");
// Succeed. The file has been delete pended now,
// because the file is still opening.
HANDLE h2 = CreateFile(L"C:\\test.txt",
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0);
// Failed with ERROR_ACCESS_DENIED. But why not ERROR_DELETE_PENDING?
Run Code Online (Sandbox Code Playgroud)
对于最后一个CreateFile函数,文件系统驱动程序返回STATUS_DELETE_PENDING。
但是Win32子系统将其转换为ERROR_ACCESS_DENIED。为什么?
我认为应该是ERROR_DELETE_PENDING,并且很好奇他们为什么这样设计。
是否有充分的理由?
我认为C++ 0x绑定要好得多,但我想在使用C++ 0x绑定之前理解旧的bind1st和2st:
struct AAA
{
int i;
};
struct BBB
{
int j;
};
// an adaptable functor.
struct ConvertFunctor : std::binary_function<const AAA&, int, BBB>
{
BBB operator()(const AAA& aaa, int x)
{
BBB b;
b.j = aaa.i * x;
return b;
}
};
BBB ConvertFunction(const AAA& aaa, int x)
{
BBB b;
b.j = aaa.i * x;
return b;
}
class BindTest
{
public:
void f()
{
std::vector<AAA> v;
AAA a;
a.i = 0;
v.push_back(a);
a.i = 1; …Run Code Online (Sandbox Code Playgroud) 我想使用stl :: set来放置一些目录路径.该集有一些特殊的目录路径,我把它.我应该找到一些输入路径的特殊父级.
有代码.我评论了一些观点.
set<wstring> special_directories;
void WhoIsMySpecialParent(const wstring& f)
{
set<wstring>::const_iterator it;
it = special_directories.upper_bound(f);
if (it == special_directories.begin())
{
printf("There isn't any special parent.");
return;
}
--it;
wprintf(L"The special parent is <%s>\n", it->c_str());
}
int _tmain(int argc, _TCHAR* argv[])
{
// These are special directories which I will manage.
// "/home" and "/home/benjamin" are not included in the special directories.
// If I want to make "/home" as special directory,
// I have to add "/home" in the …Run Code Online (Sandbox Code Playgroud) windows ×6
winapi ×5
c ×3
c++ ×3
filesystems ×2
stl ×2
c++11 ×1
dependencies ×1
device ×1
file-io ×1
function ×1
header-files ×1
inline ×1
mutex ×1
set ×1
snapshot ×1
stdcall ×1
system ×1
tree ×1
visual-c++ ×1