in regard to WinLIFT64.dll

New to FreeBASIC? Post your questions here.
Post Reply
srvaldez
Posts: 3649
Joined: Sep 25, 2005 21:54

in regard to WinLIFT64.dll

Post by srvaldez »

in regard to WinLIFT64.dll viewtopic.php?t=33182

the WinLIFT64.dll can be downloaded from http://www.objreader.com/index.php?topi ... 03#msg6503, you probably need to register in order to download

the WinLIFT.bi can be found at viewtopic.php?p=307637#p307637

I was trying to determine how to deal with the functions that return a WCHAR ptr

the following test prints the version and after a second or two it crashes

Code: Select all

#define UNICODE
#define _WIN32_WINNT &h0602

#include "WinLIFT.bi"
#inclib "WinLIFT64"

dim v as wstring ptr = new WCHAR[16]
v=skVersion()
? *v
Delete[] v

/'
7.00


------------------
(program exited with code: -1073740940)
'/
same thing with C++

Code: Select all

#include "WinLIFT.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

#pragma comment(lib,"WinLIFT64.lib")
int main(void)
{
	WCHAR* v = new WCHAR[16];
	v=skVersion();
	//printf("%ls\n", v);
	std::wcout << v << std::endl;
	delete[] v;
	return 0;
}
note: the #pragma comment(lib,"WinLIFT64.lib") is for msvc or compatible, for example the Intel C++ compiler
when compiling with the Intel compiler the exe prints the number then pauses a few seconds and then ends without crash, but the pause looks suspicious
icx test-winlift.cpp -o test-winlift
adeyblue
Posts: 357
Joined: Nov 07, 2019 20:08

Re: in regard to WinLIFT64.dll

Post by adeyblue »

This is likely overcomplicating it
dim v as wstring ptr = new WCHAR[16]
v=skVersion()
? *v
Delete[] v

Code: Select all

int main(void)
{
	WCHAR* v =skVersion();
	std::wcout << v << std::endl;
}
If the docs say that the string is allocated and you have to free it, it should tell you what to free it with - so the next line of these would then be that function to free it.
srvaldez
Posts: 3649
Joined: Sep 25, 2005 21:54

Re: in regard to WinLIFT64.dll

Post by srvaldez »

with that change the error number changes to (program exited with code: -1073740791) previously it was (program exited with code: -1073740940)
both in FreeBasic and C++
D.J.Peters
Posts: 8642
Joined: May 28, 2005 3:28
Contact:

Re: in regard to WinLIFT64.dll

Post by D.J.Peters »

with: v=skVersion()
you overwrite the C++/FreeBASIC allocated pointer with memory allocated by the library !

with Delete[] v
you (try) to deallocate a memory region allocated by the libraray not by C++/FreeBASIC !

Code: Select all

var v = skVersion()
? *v
sleep
may be it's a "const" ptr allocated by the library !

Code: Select all

dim as const wstring ptr v
Joshy
srvaldez
Posts: 3649
Joined: Sep 25, 2005 21:54

Re: in regard to WinLIFT64.dll

Post by srvaldez »

Hi Joshy
the var solution doesn't work, the wstring prints the version then crash
but I am thinking that the crash happens because the DLL needs to be unlocked with a user ID which I don't have, I was simply trying to test the DLL to possibly help Patrice Terrier
but you made me aware of my faulty logic in regards allocating memory then assigning a different pointer to the variable and then freeing memory I didn't allocate, plus we now have a leak
thanks D.J.Peters :)
Post Reply