Skip to content
/ koffi Public

about TWAINDSM.dll DSM_Entry #229

@C-Coding

Description

@C-Coding

I'm using Koffi to call the DSM_Entry function in the TWAINDSM.dll. The first step, OPENDSM, succeeds (returns 0), but the second step, USERSELECT, fails to be called successfully (returns 1). I'm wondering why, thanks.

import koffi from "koffi";

const TW_VERSION = koffi.struct("TW_VERSION", {
  MajorNum: "uint16",
  MinorNum: "uint16",
  Language: "uint16",
  Country: "uint16",
  Info: "str32",
});

const TW_IDENTITY = koffi.struct("TW_IDENTITY", {
  Id: "uint32",
  Version: TW_VERSION,
  ProtocolMajor: "uint16",
  ProtocolMinor: "uint16",
  SupportedGroups: "uint32",
  Manufacturer: "str32",
  ProductFamily: "str32",
  ProductName: "str32",
});

const dsm_name = "TWAINDSM.dll";

const twain_dll = koffi.load(dsm_name);

const entry = twain_dll.func(
  "uint16 DSM_Entry(TW_IDENTITY *pOrigin, void *pDest, uint32 DG, uint16 DAT, uint16 MSG, _Out_ TW_IDENTITY *pData)"
);
const app_id = {
  Version: {
    MajorNum: 1,
    MinorNum: 0,
    Language: 13,
    Country: 1,
    Info: "",
  },
  ProtocolMajor: 1,
  ProtocolMinor: 0,
  SupportedGroups: 2,
  Manufacturer: "twain",
  ProductFamily: "TWAIN Python Interface",
  ProductName: "TWAIN Python Interface",
};
let rv = entry(
  app_id,
  null,
  constants.DG_CONTROL, //1
  constants.DAT_PARENT, //4
  constants.MSG_OPENDSM, //769
  null
);
console.log(rv); //0

let test = {};
rv = entry(
  app_id,
  null,
  constants.DG_CONTROL, //1
  constants.DAT_IDENTITY, //3
  constants.MSG_USERSELECT, //1027
  test
);
console.log(rv); //1

here is part of twain.h

TW_UINT16 FAR PASCAL DSM_Entry( pTW_IDENTITY pOrigin,
                                pTW_IDENTITY pDest,
                                TW_UINT32    DG,
                                TW_UINT16    DAT,
                                TW_UINT16    MSG,
                                TW_MEMREF    pData);

typedef LPVOID         TW_MEMREF;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions