将代码添加到SWIG中自动生成的类

 手浪用户2602928711 发布于 2022-12-10 20:49

我正在尝试找到一种方法来为swig生成的函数添加代码.我使用了类型映射来扩展类,但在文档中找不到有关扩展特定函数的任何内容.

给出以下swig接口文件:

%module Test
%{
#include "example.h"
%}

%typemap(cscode) Example %{
    bool 64bit = SizeOf(typeof(System.IntPtr)) == 8;
    static string Path = 64bit ? "/...Path to 64 bit dll.../" : 
                                 "/...Path to 32 bit dll.../";
%}

%include "example.h"

我得到以下C#代码:

public class MyClass : global::System.IDisposable {
    ...
    bool 64bit = SizeOf(typeof(System.IntPtr)) == 8;
    static string Path = 64bit ? "/...Path to 64 bit dll.../" : 
                                 "/...Path to 32 bit dll.../";

    ...
    public static SomeObject Process(...) {     // Function defined in example.h
                                               <- I would like to add some code here.
        SomeObject ret = new SomeObject(...);

    }
    ...
}

我想在函数Process中添加一些代码,这段代码是一个调用,SetDllDirectory(Path)根据平台类型加载正确的dll.这需要在Process()通话中发生.

任何帮助是极大的赞赏!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有