本文介绍了如何写在VAPI文件void指针的typedef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个VAPI文件中使用的unixODBC,其中一项功能叫做的SQLAllocHandle

  //来自以下; sqltypes.h>
#定义SQL_API
的typedef签署短整型SQLSMALLINT;
SQLSMALLINT的typedef SQLRETURN;
无效的typedef * SQLHANDLE;//来自以下; sql.h>
#定义SQL_SUCCESS 0
#定义SQL_SUCCESS_WITH_INFO 1
#定义SQL_ERROR(-1)
#定义SQL_INVALID_HANDLE(-2)#定义SQL_HANDLE_ENV 1
#定义SQL_HANDLE_DBC 2
#定义SQL_HANDLE_STMT 3
#定义4 SQL_HANDLE_DESC#定义SQL_NULL_HANDLE 0SQLRETURN SQL_API的SQLAllocHandle(SQLSMALLINT HandleType,SQLHANDLE InputHandle要,SQLHANDLE * OutputHandle);

这是我第一次尝试写一个VAPI文件,但文件是稀缺的时刻()。

调用code应该类同这样的:

 使用的unixODBC;INT主要(字串[] args){
  手柄H;
  如果(AllocHandle(HandleType.ENV,NullHandle,输出H)== Return.SUCCESS)
  ...
}

在我特别想知道如何转换的 SQLHANDLE 键入这是真的只是一个无效* (不透明void指针)。

在换句话说,会是什么 UnixOdbc.Handle 类型看起来像VAPI文件?

我目前的做法是,以pretend,这是一个长期的:

  [C code(cheader_filename =sql.h,sqltypes.h)]
命名空间的unixODBC {
    [C code(CNAME =SQLRETURN,C preFIX =SQL_)]
    公共枚举返回{
        成功,
        SUCCESS_WITH_INFO,
        错误,
        INVALID_HANDLE
    }
    [C code(CNAME =SQLSMALLINT,C preFIX =SQL_HANDLE_)]
    公共枚举HandleType {
        ENV,
        DBC,
        STMT,
        DESC
    }
    [C code(CNAME =SQLHANDLE)]
    公共结构手柄:长{}    [C code(CNAME =SQL_NULL_HANDLE)]
    公共常量处理NULL_HANDLE;    [C code(CNAME =的SQLAllocHandle)]
    公共静态回报AllocHandle(HandleType handle_type,手柄input_handle,出手柄output_handle);
}


解决方案

您可以尝试阅读的。我会做:

  [C code(CNAME =无效)]
[紧凑]
公共类手柄{
   [C code(CNAME =的SQLAllocHandle)]
   公共静态回报alocate_handle(HandleType类型,处理input_handle,出处理output_handle?);
...
}

根本不顾 SQL_NULL_HANDLE 的结合;它不会做任何有用的东西。

I'm trying to write a VAPI file to use unixODBC, one of the functions is called SQLAllocHandle:

// From <sqltypes.h>
#define SQL_API
typedef signed short int SQLSMALLINT;
typedef SQLSMALLINT      SQLRETURN;
typedef void *           SQLHANDLE;

// From <sql.h>
#define SQL_SUCCESS                0
#define SQL_SUCCESS_WITH_INFO      1
#define SQL_ERROR                 (-1)
#define SQL_INVALID_HANDLE        (-2)

#define SQL_HANDLE_ENV             1
#define SQL_HANDLE_DBC             2
#define SQL_HANDLE_STMT            3
#define SQL_HANDLE_DESC            4

#define SQL_NULL_HANDLE            0

SQLRETURN SQL_API SQLAllocHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE *OutputHandle);

It's my first try to write a vapi file, but the documentation is scarce at the moment (Vala vapi files documentation).

The calling code should look similiar to this:

using UnixOdbc;

int main(string[] args) {
  Handle h;
  if (AllocHandle (HandleType.ENV, NullHandle, out h) == Return.SUCCESS)
  ...
}

In particular I'd like to know how to convert the SQLHANDLE type which is really just a void * (opaque void pointer).

In other words, what would the UnixOdbc.Handle type look like in the vapi file?

My current approach is to pretend that it is a long:

[CCode (cheader_filename = "sql.h, sqltypes.h")]
namespace UnixOdbc {
    [CCode (cname = "SQLRETURN", cprefix = "SQL_")]
    public enum Return {
        SUCCESS,
        SUCCESS_WITH_INFO,
        ERROR,
        INVALID_HANDLE
    }
    [CCode (cname = "SQLSMALLINT", cprefix = "SQL_HANDLE_")]
    public enum HandleType {
        ENV,
        DBC,
        STMT,
        DESC
    }
    [CCode (cname = "SQLHANDLE")]
    public struct Handle: long {}

    [CCode (cname = "SQL_NULL_HANDLE")]
    public const Handle NULL_HANDLE;

    [CCode (cname = "SQLAllocHandle")]
    public static Return AllocHandle (HandleType handle_type, Handle input_handle, out Handle output_handle);
}
解决方案

You can trying reading the guide for legacy VAPI files. I would make:

[CCode(cname = "void")]
[Compact]
public class Handle {
   [CCode(cname = "SQLAllocHandle")]
   public static Return alocate_handle(HandleType type, Handle? input_handle, out Handle?  output_handle);
...
}

Simply disregard the binding of SQL_NULL_HANDLE; it doesn't do anything useful.

这篇关于如何写在VAPI文件void指针的typedef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 09:05