小编Mic*_*rus的帖子

通过 Clozure CL 与 Windows API 交互

我想通过 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)

获取/设置正确的方法签名

以下是我认为调用它的一般步骤,但我不确定每个步骤是如何进行的:

  • 检索 CCL 为此函数生成的签名,以便我知道如何调用它。
  • 使用 为其提供不同的函数签名external-call
  • 定义一个 FFI 结构或类来保存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)

common-lisp ffi ccl

5
推荐指数
0
解决办法
531
查看次数

在C#中读写非常大的文本文件

我有一个非常大的文件,大小近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)

.net c# wpf streamwriter streamreader

5
推荐指数
1
解决办法
4770
查看次数

将Platform Toolset更改为v140_xp时,"Windows.h:没有此类文件或目录"错误

我试图编译Windows XP的应用程序; 正常的可执行文件给出错误:

"... 不是有效的Win32应用程序."

我读到我可以通过更改Platform Toolset来创建与XP兼容的可执行文件Visual Studio 2015 - Windows XP (v140_xp),但是当我这样做然后尝试编译它时会给我以下错误:

无法打开包含文件:'Windows.h':没有这样的文件或目录

无法从注册表中找到WindowsSdkDir_71A变量.TargetFrameWorkVersion或Platform工具集可能设置为无效的版本号.

如何使用此工具集版本进行编译?

c++ windows-xp visual-c++ visual-studio-2015

4
推荐指数
1
解决办法
1844
查看次数

构造函数调用序列

请考虑以下代码:

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

3
推荐指数
1
解决办法
183
查看次数

什么是TCHAR字符串和Win32 API函数的"A"或"W"版本?

什么是TCHAR字符串,例如LPTSTRLPCTSTR我如何使用它们?当我在Visual Studio中创建一个新项目时,它为我创建了这个代码:

#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[])
{
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

例如,我如何连接所有命令行参数?

如果我想打开第一个命令行参数给出的名称的文件,我该怎么做?Windows API定义了许多函数的"A"和"W"版本,例如CreateFile,CreateFileACreateFileW; 那么这些如何彼此不同以及我应该使用哪一个?

c c++ winapi tchar visual-studio

2
推荐指数
1
解决办法
1341
查看次数

指定不绑定临时对象的`const int&`

有没有办法将常量引用指定为不绑定临时值的参数类型(函数)?也就是说,是否有一种标准方法来指定引用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&&,然后不定义它,但这会产生错误的想法,只会导致链接器错误.

c++ reference c++11

2
推荐指数
1
解决办法
62
查看次数

编译需要#include "stdafx.h"

我刚开始使用 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++ visual-studio c++11

1
推荐指数
1
解决办法
4527
查看次数