我想通过 Clozure CL 的外部函数接口调用 Windows API 函数,但我遇到了一些问题,因为我找到的文档相当稀缺。
作为一个足够丰富的示例,我尝试调用SHGetKnownFolderPath。它的签名是
HRESULT SHGetKnownFolderPath(const GUID &rfid, DWORD dwFlags,
HANDLE hToken, PWSTR *ppszPath );
Run Code Online (Sandbox Code Playgroud)
我可以使用以下命令来获取函数的入口点:
(open-shared-library "shell32.dll")
> #<SHLIB SHELL32.dll #x1234>
(external "SHGetKnownFolderPath")
> #<EXTERNAL-ENTRY-POINT "SHGetKnownFolderPath" (#x12345) SHELL32.dll #x123456>
Run Code Online (Sandbox Code Playgroud)
以下是我认为调用它的一般步骤,但我不确定每个步骤是如何进行的:
external-call。GUID(第一个参数)viadef-foreign-type或相关构造。CoTaskMemFree来释放 指向的内存*ppszPath。我对最终代码的一般形式的猜测是
(defun get-known-folder (guid)
(let ((ffi-guid (allocate-ffi-memory-from-guid guid))
(ffi-path ffi-version-of-nil)
(path nil))
(external-call "SHGetKnownFolderPath" ...) ;; Pass ffi-guid and ffi-path …Run Code Online (Sandbox Code Playgroud) 我有一个非常大的文件,大小近2GB.我正在尝试编写一个进程来读取文件并在没有第一行的情况下将其写出来.我几乎只能一次读写一行,这需要永远.我可以打开它,删除第一行并在TextPad中保存得更快,尽管这仍然很慢.
我使用此代码来获取文件中的记录数:
private long getNumRows(string strFileName)
{
long lngNumRows = 0;
string strMsg;
try
{
lngNumRows = 0;
using (var strReader = File.OpenText(@strFileName))
{
while (strReader.ReadLine() != null)
{
lngNumRows++;
}
strReader.Close();
strReader.Dispose();
}
}
catch (Exception excExcept)
{
strMsg = "The File could not be read: ";
strMsg += excExcept.Message;
System.Windows.MessageBox.Show(strMsg);
//Console.WriteLine("Thee was an error reading the file: ");
//Console.WriteLine(excExcept.Message);
//Console.ReadLine();
}
return lngNumRows;
}
Run Code Online (Sandbox Code Playgroud)
这只需要几秒钟就可以运行.当我添加以下代码时,它需要永远运行.难道我做错了什么?为什么写入会增加这么多时间?关于如何让它更快的任何想法?
private void ProcessTextFiles(string strFileName)
{
string strDataLine;
string strFullOutputFileName;
string strSubFileName;
int intPos; …Run Code Online (Sandbox Code Playgroud) 我试图编译Windows XP的应用程序; 正常的可执行文件给出错误:
"... 不是有效的Win32应用程序."
我读到我可以通过更改Platform Toolset来创建与XP兼容的可执行文件Visual Studio 2015 - Windows XP (v140_xp),但是当我这样做然后尝试编译它时会给我以下错误:
无法打开包含文件:'Windows.h':没有这样的文件或目录
无法从注册表中找到WindowsSdkDir_71A变量.TargetFrameWorkVersion或Platform工具集可能设置为无效的版本号.
如何使用此工具集版本进行编译?
请考虑以下代码:
class A {};
class B : virtual public A {};
class C : virtual public A {};
class D : public B, public C {};
D d;
Run Code Online (Sandbox Code Playgroud)
Visual Studio的编译器首先调用类B的构造函数,然后调用类C的构造函数.但这是一个规则,即ISO C++标准是否保证构造函数调用的顺序?
c++ inheritance constructor virtual-inheritance language-lawyer
什么是TCHAR字符串,例如LPTSTR和LPCTSTR我如何使用它们?当我在Visual Studio中创建一个新项目时,它为我创建了这个代码:
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
例如,我如何连接所有命令行参数?
如果我想打开第一个命令行参数给出的名称的文件,我该怎么做?Windows API定义了许多函数的"A"和"W"版本,例如CreateFile,CreateFileA和CreateFileW; 那么这些如何彼此不同以及我应该使用哪一个?
有没有办法将常量引用指定为不绑定临时值的参数类型(函数)?也就是说,是否有一种标准方法来指定引用const但它只能绑定到非临时值,并尝试绑定到临时导致编译器错误¹?
例如,在类的构造函数的情况下X,
class X
{
public:
X(const int &value)
: mValue(value)
{}
private:
const int &mValue;
};
Run Code Online (Sandbox Code Playgroud)
什么是确保这一点的好方法
class Y
{
public:
/* ... */
X* GetXForValue() const
{
return new X(mValue);
}
private:
int mValue;
};
Run Code Online (Sandbox Code Playgroud)
编译,但用临时调用,例如X x(100);,它不?
¹)我可以重载函数int&&,然后不定义它,但这会产生错误的想法,只会导致链接器错误.
我刚开始使用 Visual Studio 2013。直到我开始将 #include "stdafx.h" 放在每个 cpp 文件的开头,我的代码才会编译。当其他人通过Linux终端编译我的代码时,这会导致任何问题吗?如果我简单地从下面的代码中删除 #include "stdafx.h",它会用 g++ 编译 C++11 吗?
#include "stdafx.h"
#include<iostream>
using std::cout; using std::endl; using std::cin;
using namespace std;
int main()
{
cout << "This is an awesome game to play with your friends!"
<< endl << "You have to pick an integer between 10 and 49 and type it in"
<< endl << "Then your friend has to pick an integer between 50 and 99 and type it in."
<< endl …Run Code Online (Sandbox Code Playgroud) c++ ×5
c++11 ×2
.net ×1
c ×1
c# ×1
ccl ×1
common-lisp ×1
constructor ×1
ffi ×1
inheritance ×1
reference ×1
streamreader ×1
streamwriter ×1
tchar ×1
visual-c++ ×1
winapi ×1
windows-xp ×1
wpf ×1