在Windows中,ctypes.cdll.msvcrt
导入ctypes模块时对象自动存在,并且它根据文档表示msvcrt
Microsoft C++运行时库.
但是,我注意到还有一个find_msvcrt函数"return the filename of the VC runtype library used by Python"
.
它进一步指出, "If you need to free memory, for example, allocated by an extension module with a call to the free(void *), it is important that you use the function in the same library that allocated the memory."
所以我的问题是,ctypes.cdll.msvcrt
我已经拥有的库与我可以使用该find_msvcrt
函数加载的库之间的区别是什么?在什么具体情况下他们可能不是同一个图书馆?
我有一大堆代码,用/ MT编译(即期望静态链接到CRT).我需要将它与静态第三方库结合使用,该库是用/ MD构建的(即期望动态链接CRT).
理论上是否可以将两者连接成一个可执行文件而不重新编译?
如果我链接到/ nodefaultlib:msvcrt,我最终会得到少量未定义的引用__imp__wgetenv
.我很想尝试在我自己的代码中实现这些功能,转发到wgetenv
等等.这值得尝试,还是我会直接进入下一个问题?
不幸的是,我禁止将第三方代码打包成一个单独的DLL的简单选项: - /
我有代码,由于各种原因,我正在尝试从C运行时移植到使用Windows Heap API的代码.我遇到了一个问题:如果我重定向malloc
/ calloc
/ realloc
/ free
调用HeapAlloc
/ HeapReAlloc
/ HeapFree
(使用GetProcessHeap
的手柄),内存似乎是正确分配(无不良指针返回,没有抛出异常),但我的图书馆porting因某种原因说"未能分配内存".
我已尝试使用Microsoft CRT(使用下面的Heap API)和另一个公司的运行时库(使用下面的Global Memory API); 两者的malloc适用于库,但由于某些原因,直接使用Heap API不起作用.
我已经检查过分配不是太大(> = 0x7FFF8字节),而它们不是.
我能想到的唯一问题是内存对齐; 那是这样吗?或者除此之外,Heap API和我不知道的CRT内存API有根本区别吗?
如果是这样,它是什么?如果没有,那么为什么静态 Microsoft CRT(包含在Visual Studio中)在调用之前malloc
/ calloc
之前需要一些额外的步骤HeapAlloc
?我怀疑存在差异,但我想不出它可能是什么.
谢谢!
我正在运行我在Visual Studio 2010中构建的程序,该程序使用第三方DLL"ABC.DLL".我在Windows 7 64位上.
但是,由于一个DLL,它无法运行.在此DLL上运行Dependency walker时,我收到以下错误:
错误:"...\ABC.DLL"的Side-by-Side配置信息包含错误.应用程序无法启动,因为它的并排配置不正确.请参阅应用程序事件日志或使用命令行sxstrace.exe工具获取更多详细信息(14001).
缺少依赖关系MSCVR80.DLL和MSVCP80.DLL.
我已经尝试了以下主题中的所有解决方案,但我仍然遇到同样的错误.
ABC.DLL是在Visual Studio 2005中构建的第三方库,我无法重建它.
我已经安装了Visual Studio C++ 2005 Redistributable,并尝试复制从另一台计算机上获取的DLL(因为我的计算机中没有它)并且没有任何作用.
dependencies msvcrt side-by-side visual-studio-2010 visual-c++
我想msvcrt.getch()
在Eclipse中使用PyDev来读取一个signe char,但我发现它只是不起作用(但它可以在Windows控制台中运行).
知道该怎么办?
所以,我有一个C++库,其中包含MSVCRT的静态链接副本.我希望任何人都可以将我的库与任何版本的MSVC Runtime一起使用.实现这一目标的最佳方法是什么?
事情已经完成,我已经非常小心了.
然而,我仍然有一些简单的代码导致堆损坏.
我的库中有一个这样的对象:
class Foos
{
public: //There is an Add method, but it's not used, so not relevant here
DLL_API Foos();
DLL_API ~Foos();
private:
std::map<std::wstring, Foo*> map;
};
Foos::~Foos()
{
// start at the begining and go to the end deleting the data object
for(std::map<std::wstring, Foo*>::iterator it = map.begin(); it != map.end(); it++)
{
delete it->second;
}
map.clear();
}
Run Code Online (Sandbox Code Playgroud)
然后我从我的应用程序中使用它,如下所示:
void bar() {
Foos list;
}
Run Code Online (Sandbox Code Playgroud)
从任何地方调用此函数后,我收到有关堆栈损坏的调试警告.如果我真的让它耗尽,它实际上会破坏堆栈和段错误.
我的调用应用程序是使用Visual Studio 2012平台工具编译的.该库是使用Visual Studio 2010平台工具编译的.
这只是我绝对不应该做的事情,还是我实际上违反了使用多个运行时的规则?
当我尝试在x86机器上使用MC++编译器(vs2010)为x86 CPU构建的x64机器上运行exe时,我收到以下错误:
我已经在第二台(x64)计算机上安装了visual studio 2012(以及可重新分发的Visual C++ 2012 Update 4,x86和x64).
快速搜索告诉我"MSVCR100.dll"已存在于"C:\ Windows\System32"中.
我尝试安装Microsoft Visual C++ 2010 Redistributable,但它退出时出现错误,告诉我已安装了高级版本.
请指导我做错了什么.:)
我正在使用 Visual Studio 2017 编译一个程序,该程序与 libusb 的预编译静态版本链接,可在此处获得。
当我尝试链接它时,我得到了一些像这些未解析的符号,答案指向我legacy_stdio_definitions.lib
解决了所有链接器错误,除了:
unresolved external symbol __imp__iob
Run Code Online (Sandbox Code Playgroud)
微软的这个页面谈论legacy_stdio_definitions.lib
并说它提供__imp___iob
但没有提到__imp__iob
(注意不同数量的下划线)。
这里发生了什么?
(另外,是的,混合 CRT 版本是一个坏主意,我真的应该从源代码编译 libusb。我知道。)
我被困在这里(下图),需要通过它才能读取我的文本。我还有 text.txt 文件。该程序本身无法使用 python 2 运行。使用 python 2 它在这里给了我一个错误:print(last_suggestion, end=' ', flush=True)
。
train_data = 'text.txt'
first_possible_words = {}
second_possible_words = {}
transitions = {}
def expandDict(dictionary, key, value):
if key not in dictionary:
dictionary[key] = []
dictionary[key].append(value)
def get_next_probability(given_list): #returns dictionary
probability_dict = {}
given_list_length = len(given_list)
for item in given_list:
probability_dict[item] = probability_dict.get(item, 0) + 1
for key, value in probability_dict.items():
probability_dict[key] = value / given_list_length
return probability_dict
def trainMarkovModel():
for line in open(train_data):
tokens = line.rstrip().lower().split() …
Run Code Online (Sandbox Code Playgroud) msvcrt ×10
visual-c++ ×5
c++ ×3
python ×2
build ×1
ctypes ×1
dependencies ×1
deployment ×1
dll ×1
eclipse ×1
heap ×1
heapalloc ×1
macos ×1
malloc ×1
pydev ×1
python-3.x ×1
side-by-side ×1
winapi ×1