Error while using ESENT.dll in Golang
Hello, I'm trying to use the ESENT.dll library in my Golang application. Thanks to the Microsoft documentation, I created a little sample of code that :
- Create the instance (JetCreateInstance)
JET_ERR JET_API JetCreateInstance(
__out JET_INSTANCE* pinstance,
__in_opt const tchar* szInstanceName
);
type JET_INSTANCE uintptr
instance JET_INSTANCE
fmt.Print("Call JetCreateInstance... ")
retCreate, _, errCreate := esentDLL.NewProc("JetCreateInstance").Call(
uintptr(unsafe.Pointer(&instance)),
0,
)
- Initialize the instance (JetInit)
JET_ERR JET_API JetInit(
__in_out_opt JET_INSTANCE* pinstance
);
fmt.Print("Call JetInit... ")
retInit, _, errInit := esentDLL.NewProc("JetInit").Call(
uintptr(unsafe.Pointer(&instance)),
)
- Create the session (JetBeginSession)
JET_ERR JET_API JetBeginSession(
__in JET_INSTANCE instance,
__out JET_SESID* psesid,
__in_opt JET_PCSTR szUserName,
__in_opt JET_PCSTR szPassword
);
type JET_SESID uintptr
sesid JET_SESID
fmt.Print("Call JetBeginSession... ")
retBegin, _, errBegin := esentDLL.NewProc("JetBeginSession").Call(
uintptr(instance),
uintptr(unsafe.Pointer(&sesid)),
0,
0,
)
- Attache the ESEDB database (JetAttachDatabase)
JET_ERR JET_API JetAttachDatabase(
__in JET_SESID sesid,
__in const tchar* szFilename,
__in JET_GRBIT grbit
);
type JET_DBID uint64
dbid JET_DBID
fmt.Print("Call JetAttachDatabase... ")
retAttach, _, errAttach := esentDLL.NewProc("JetAttachDatabase").Call(
uintptr(sesid),
uintptr(unsafe.Pointer(&pesedbPath)),
0,
)
- Open the ESEDB database (JetOpenDatabase)
JET_ERR JET_API JetOpenDatabase(
__in JET_SESID sesid,
__in const tchar* szFilename,
__in_opt const tchar* szConnect,
__out JET_DBID* pdbid,
__in JET_GRBIT grbit
);
fmt.Print("Call JetOpenDatabase... ")
retOpen, _, errOpen := esentDLL.NewProc("JetOpenDatabase").Call(
uintptr(sesid),
uintptr(unsafe.Pointer(&pesedbPath)),
0,
uintptr(unsafe.Pointer(&dbid)),
0,
)
Var nammed "pesedbPath" is declared as global variable at the beginning of my code. During tests, I have a copy of a SRUDB.dat file directly in my code folder :
esedbPath, err := syscall.UTF16PtrFromString(".\\SRUDB.dat")
A function called "callResult" handle error by controlling the value of "retXxxx" :
func callResult(ret uintptr, err error) {
if ret != 0 {
fmt.Print("Error : ", uintptr(ret), " - ")
} else {
fmt.Print("Done : ", uintptr(ret), " - ")
}
fmt.Println(err)
}
According to Microsoft documentation, 0 mean that the function succeed. During my tests, I had the following results :
[Running] go run "c:\Users\Xxxxx\Xxxxxx\Xxxxxx\Go\src\esentest\main.go"
Call JetCreateInstance... Done : 0 - The operation completed successfully.
Call JetInit... Done : 0 - The system could not find the environment option that was entered.
Call JetBeginSession... Done : 0 - The operation completed successfully.
Call JetAttachDatabase... Error : 4294965485 - The system cannot find the file specified.
Call JetOpenDatabase... Error : 4294966093 - The system cannot find the file specified.
Call JetGetDatabaseInfo... Error : 4294966286 - The operation completed successfully.
Call JetCloseDatabase... Error : 4294966286 - The operation completed successfully.
Call JetDetachDatabase... Done : 0 - The operation completed successfully.
Call JetEndSession... Done : 0 - The operation completed successfully.
Call JetTerm... Done : 0 - The system could not find the environment option that was entered.
JetCreateInstance and JetBeginSession return 0 and error "The operation completed successfully" so no problem. JetInit return 0, so apparently no error but error return "The system could not find the environment option that was entered". JetAttachDatabase and JetOpenDatabase return error "The system cannot find the file specified" and a value that doesn't correspond to any of the error codes indicated in the docimentation. If I understand well, API could not find "SRUDB.dat". But I can't understand why... Could you help me please ? Thanks !