DLL questions
[1/6] from: robert:muench:robertmuench at: 8-Jan-2004 21:59
Hi, is there a trick how I can write some log-messages to the console from
a DLL that I use in a Rebol program? I tried printf and fprintf... but no
output is shown. I start my Rebol program thru from the console:
view.exe script.r
I thought that Rebol might need an already opened cosole in that printf
works. But it doesn't work.
Next problem: How does a Rebol routine! look like for a function "void
func()"? I tried
func: make rountine! [] lib "my_func"
And last but not least I'm having a problem where Rebol crashes at a
specific point. I have C++ code like this:
static Type my_data;
static Type2 root;
extern "C" {
long _export new_stuff(char* name) {
Type my_tmp_data(name, E4_METAKIT);
my_data = my_tmp_data;
if(!my_tmp_data.valid()) {
return false;
}
return true;
}
}
The problem is the assignment. If I comment it, it works. There is a
copy-ctor in the class for Type. In a pure C++ program is works. Could
this be a problem with the char* and memory handling thru Rebol?
I found out that View is very picky about this. The program runs, but View
doesn't terminate in such a case and is left over as zombie process.
--
Robert M. Münch
Management & IT Freelancer
Mobile: +49 (177) 245 2802
http://www.robertmuench.de<
[2/6] from: robert:muench:robertmuench at: 10-Jan-2004 13:41
Hi, some more strange problmes. Here is my Rebol code snippet:
graphit-lib: load/library %graphit.dll
new-storage: make routine! [
"Create new storage"
storage [string!] "Name of storage file"
return: [integer!]
] graphit-lib "new_storage"
close-storage: make routine! [
dummy [integer!]
] graphit-lib "close_storage"
get-block: make routine! [
name [string!]
] graphit-lib "get_block"
; close-storage 1
print new-storage "rebol-test.db"
get-block "test"
; close-storage 1
free graphit-lib
halt
And here the C code for the DLL graphit.dll Note: It's just test code,
don't look at the function names.
#include "e4graph.h"
char *test;
extern "C" {
long _export new_storage(char* name) {
e4_Storage storage("test", E4_METAKIT);
// get Root node so that we have a place to start from
e4_Node root;
if(!storage.GetRootNode(root)) {
return false;
}
return true;
}
void _export close_storage(int a) {
test = new char(200);
return;
}
void _export get_block(char* name) {
return;
}
}
As soon as I call "close_storage" from my Rebol script it hangs. I really
don't know where the problem comes from. I know it has something to do
with the case, when I try to do anything WRT memory operations. Adding a
static global, allocating memory etc. than Rebol hangs.
--
Robert M. Münch
Management & IT Freelancer
Mobile: +49 (177) 245 2802
http://www.robertmuench.de<
[3/6] from: greggirwin:mindspring at: 10-Jan-2004 10:06
Hi Robert,
I haven't written any C-side stuff to interface with REBOL. Have you
tried tests with each datatype to see if it's something related only
to strings? I know with Windows API stuff it's important to
preallocate space in many cases.
-- Gregg
[4/6] from: robert:muench:robertmuench at: 10-Jan-2004 19:57
On Sat, 10 Jan 2004 10:06:18 -0700, Gregg Irwin
<[greggirwin--mindspring--com]> wrote:
> I haven't written any C-side stuff to interface with REBOL. Have you
> tried tests with each datatype to see if it's something related only
> to strings? I know with Windows API stuff it's important to
> preallocate space in many cases.
Hi, I don't think this is the problem. As I get a char* that's allocated
by Rebol, it should work. Maybe it's releated to some DLL startup/shutdown
problem. Or it could be a side-effect of the e4graph library.
Is anyone interested in the code? If so, I'm going to prepare a ZIP with
all you need, so you can fire up your C compiler and check out yourself.
--
Robert M. Münch
Management & IT Freelancer
Mobile: +49 (177) 245 2802
http://www.robertmuench.de<
[5/6] from: antonr:iinet:au at: 11-Jan-2004 17:26
Have you tried recycle before free library ?
Also maybe unset some words.
Anton.
[6/6] from: robert:muench:robertmuench at: 11-Jan-2004 11:40
On Sun, 11 Jan 2004 17:26:57 +1100, Anton Rolls <[antonr--iinet--net--au]>
wrote:
> Have you tried recycle before free library ?
Hi, this doesn't help because Rebol hangs as soon as I call a function
that does some memory stuff. Way before the library is released. Ok, for
those interested I have put together a ZIP with all the stuff. You can
download it at:
http://www.robertmuench.de/download/rebol-dll.zip
Everything you need is included. You don't need to tweak around with
e4graph, just try to allocate some memory. Robert<