IonicWind Software

IWBasic => General Questions => Topic started by: RitchieF on August 09, 2008, 03:19:31 AM

Title: DLL-Import fails
Post by: RitchieF on August 09, 2008, 03:19:31 AM
Hi Paul,
thanks for your help at the CodingMonkeys-Forum.
I copied your code into EBasic, added $use "C:\Programme\EBDev\libs\sed.lib" at the beginning and compiled it to a Windows-Target.

But the Program halts with an error.
So I compiled it to a debug-exe and the compiler tells me now:
Loading DLL : c:\WINDOWS\System\Kernel32.dll
First chance exception : Address 0x100011F8 Access Violation.
Final chance exception: Address 0x100011F8 Access Viiolation.

And in the Call Stack-Tab the message comes up:
Call stack:
SED! fed + 312
KERNEL32! IsDBCSLeadByte + 1512
KERNEL32! IsDBCSLeadByte + 1178
KERNEL32! MakeCriticalSectionGlobal + 3542

Could this be a Windows98 Problem anyway ?

Thanks,
Richard
Title: Re: DLL-Import fails
Post by: Ionic Wind Support Team on August 09, 2008, 10:44:34 AM
Try changing the string in the UDT to a WSTRING.  And most likely it will fail on 98 anyway since that DLL looks like it is using Unicode.  Microsoft used to have a download called "Microsoft Layer for Unicode" which allowed unicode code to run on 9x systems.  Don't know if they still have it available or not.

Paul.
Title: Re: DLL-Import fails
Post by: RitchieF on August 10, 2008, 03:17:52 AM
Paul,
I tried everything you wrote and even had the unicows.dll on my system. But as you mentioned it fails. So I'm gonna cancel this SED-Project and try it with string-functions.

Anyhow I think that actually I don't need regex-capabilities to solve my problem. I just want to extract in G-Code-Programs the X- or Y-Coordinates, do some calculations and write them back.

I wrote a little autoit-script which does this job fine but since G-Code can be very large programs it is rather slow in converting.
So I wanted to convert it to EBasic to make it faster but I am hobby-programmer and those programming languages are not so easy to handle for a spare time programmer like me.

Thank you all the same!

Richard
Title: Re: DLL-Import fails
Post by: sapero on August 10, 2008, 04:16:29 AM
Richard, if you look at the sources, you'll see that parameters and return value are defined as BSTR, a special type of WSTRING.
So you have to pass strings in this way:

EDIT: working example is 5 posts bellow

typedef BSTR pointer
declare import, SysAllocString(wstring p),BSTR
' or just $include "ole2.inc"

BSTR in, regexp, result

in = SysAllocString(L"jerry")
regexp = SysAllocString(L"[r]+")

result = sed(in, regexp)

if (result <> 0)
   print w2s(*<wstring>result)
   FreeComString(result)
endif

' free in and regexp when finished
FreeComString(in)
FreeComString(regexp)
Title: Re: DLL-Import fails
Post by: mrainey on August 10, 2008, 08:35:39 AM
Hi Richard,

I'm a retired CNC programmer, and curious about what you're up to.  If you get to a point where you'd like some ideas, I might be able to help a little.


                                                              Mike
Title: Re: DLL-Import fails
Post by: RitchieF on August 10, 2008, 08:53:53 AM
Hi Mike,

take a look here:

http://vectric.com/forum/viewtopic.php?t=656&highlight= (http://vectric.com/forum/viewtopic.php?t=656&highlight=)


This script I want to write in EBasic to make it faster.

Richard
Title: Re: DLL-Import fails
Post by: RitchieF on August 10, 2008, 09:24:21 AM
Hi sapero,
thanks for your help.

The following code runs here without error, but the result shown in the messagebox is wrong.

Richard

$use "C:\Programme\EBDev\libs\sed.lib"

typedef BSTR pointer

BSTR in, regexp ,result

DECLARE IMPORT, SysAllocString(wstring p),bstr
DECLARE IMPORT, SysFreeString(pointer bstr)
DECLARE IMPORT, SysStringLen(pointer bstr),int

DECLARE IMPORT,sed(in as bstr,regexp as bstr ),string
 
in = SysAllocString(L"jerry")
regexp = SysAllocString(L"[r]+")

result = sed(in,regexp)

if (result <> 0)   
messagebox (0,W2S(*<wstring>result),"RESULT",@MB_OK)
SysFreeString(result)
endif

' free in and regexp when finished
SysFreeString(in)
SYSFreeString(regexp)
SysFreeString(result)

Title: Re: DLL-Import fails
Post by: Ionic Wind Support Team on August 10, 2008, 02:24:41 PM
The return would be a bstr as well.

DECLARE IMPORT,sed(in as bstr,regexp as bstr ),bstr
...


Then use Sapero's code.

result = sed(in, regexp)

if (result <> 0)
   print w2s(*<wstring>result)
   FreeComString(result)
endif

The BSTR is a unicode string, 2 bytes per character so you will need to use it as illustrated or you will get odd results.

Paul.
Title: Re: DLL-Import fails
Post by: sapero on August 10, 2008, 03:03:26 PM
It was my mistake, I always used unicode strings for BSTR, but a BSTR can store ansi string (and any binary data). The SED function will work with ansi BSTR:
$use "sed.lib"
'$include "ole2.inc"
typedef BSTR pointer
DECLARE IMPORT,sed(BSTR in,BSTR regexp),BSTR
DECLARE IMPORT,SysAllocStringByteLen(pointer InitString, int totalBstrSize),BSTR
DECLARE IMPORT,SysFreeString(BSTR p)
BSTR inout, regexp, result

'use two temporary pointers to allocate ansi BSTR
pointer psz_inout, psz_regexp

psz_inout  = "In diesem Text soll jedes e durch ein X ersetzt werden" ' in this text any 'e' will be replaced with 'X'
psz_regexp = "s/e/X/g"

inout  = SysAllocStringByteLen(psz_inout, len(*<string>psz_inout))
regexp = SysAllocStringByteLen(psz_regexp, len(*<string>psz_regexp))

result = sed(inout, regexp)
MessageBox(0, *<string>result, *<string>inout, 0)

SysFreeString(result)
SysFreeString(inout)
SysFreeString(regexp)
Title: Re: DLL-Import fails
Post by: RitchieF on August 11, 2008, 10:16:46 AM
Thanks sapero, Thanks Paul !

Works great here.

Richard