November 01, 2025, 09:32:40 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


DLL-Import fails

Started by RitchieF, August 09, 2008, 03:19:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RitchieF

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

Ionic Wind Support Team

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.
Ionic Wind Support Team

RitchieF

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

sapero

August 10, 2008, 04:16:29 AM #3 Last Edit: August 10, 2008, 03:17:57 PM by sapero
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)

mrainey

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
Software For Metalworking
http://closetolerancesoftware.com

RitchieF

Hi Mike,

take a look here:

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


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

Richard

RitchieF

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)


Ionic Wind Support Team

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.
Ionic Wind Support Team

sapero

August 10, 2008, 03:03:26 PM #8 Last Edit: August 10, 2008, 03:13:11 PM by sapero
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)

RitchieF

Thanks sapero, Thanks Paul !

Works great here.

Richard