DLL & C Connect

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

DLL & C Connect

diego park

Hey,

I am having problems with DLL & C Connect in VisualWorks 7.4nc. I admit I had spent little time investigating -just read the documentation-, but I want to waste as little as possible time in this (accidental) issue and focus on the main problem.

We are working with 3D Robot Soccer Simulator (in particular, version 1.5a) and it expects a DLL to export methods Create, Strategy and Destroy. I am thinking of building a DLL that only forwards messages to VisualWorks to do the actual processing work. We have a DLL that already that this job but it's connecting to VisualSmalltalk, which is somewhat messy to work with.

So, suppose I want to send a message to a class --I thought of a class instead of an instance, to avoid dealing with problems raised from GC pointers reallocation, maybe. For the examples I read in the documentation, one possibility is to send a message from Smalltalk with the receiver, and get the class through UPclass(aReceiver) and finally send a message back to Smalltalk with the actual message (say, StrategyInterface>>strategy) . That is, I am only starting a message sequence from Smalltalk to know the receiver's class (memory address?). Is it possible to avoid this first message and refer directly to a Smalltalk class straight from C? Thus, I want to start the message-send sequence fom C (instead of sending a message from Smalltalk, like <C: void foo(_oop self, ...)>), so I was wondering if it's possible to send a message (like UPCsendMessage0) referencing directly to a class, maybe calling UPclass(...).

I hope you understood the issue and any help is appretiated.

Thanks in advance.

Best wishes,
Diego Park
Reply | Threaded
Open this post in threaded view
|

Re: DLL & C Connect

Reinout Heeck-2
I am not a DLLCC guru, but here's my 2 cents worth:

-VisualWorks can not be wrapped by (or as) a dll yet, so you'll need to
figure out how both VisualWorks and the other side can bind to your dll
while sharing data (and in a thread-safe way).

-Push as much of the nitty gritty into Smalltalk as possible, in your
case I would suggest write your dll such that VisualWorks can register
functions with it that will return classes, send particular messages
etc. It is trivial to pass a block from VisualWorks as a callback into
the dll, the block can do the low-level messaging, iow you shouldn't
need to use UPClass, UPSendMessage etc from your C code, you simply need
to call the *function* that VW passed to your dll at initialization time.
So at init time from Smalltalk you do something like
   yourDll classFoo: (CCallback do: [Foo]);
   yourDll classBar: (CCallback do: [Bar]);
   yourDll sendBaz: (CCallback do: [ :receiver :arg | receiver baz: arg])

Now your C code can simply call a registered classX function to get the
class' oop and immediately follow with a call to a registered sendXX
function passing in the class and possibly other arguments.

I think this yields simple C code as well as decoupling sufficiently to
be able to experiment with different class implementations.


HTH,

Reinout
-------


diego park wrote:

> Hey,
>
> I am having problems with DLL & C Connect in VisualWorks 7.4nc. I admit
> I had spent little time investigating -just read the documentation-, but
> I want to waste as little as possible time in this (accidental) issue
> and focus on the main problem.
>
> We are working with 3D Robot Soccer Simulator (in particular, version
> 1.5a) and it expects a DLL to export methods Create, Strategy and
> Destroy. I am thinking of building a DLL that only forwards messages to
> VisualWorks to do the actual processing work. We have a DLL that already
> that this job but it's connecting to VisualSmalltalk, which is somewhat
> messy to work with.
>
> So, suppose I want to send a message to a class --I thought of a class
> instead of an instance, to avoid dealing with problems raised from GC
> pointers reallocation, maybe. For the examples I read in the
> documentation, one possibility is to send a message from Smalltalk with
> the receiver, and get the class through UPclass(aReceiver) and finally
> send a message back to Smalltalk with the actual message (say,
> StrategyInterface>>strategy) . That is, I am only starting a message
> sequence from Smalltalk to know the receiver's class (memory address?).
> Is it possible to avoid this first message and refer directly to a
> Smalltalk class straight from C? Thus, I want to start the message-send
> sequence fom C (instead of sending a message from Smalltalk, like <C:
> void foo(_oop self, ...)>), so I was wondering if it's possible to send
> a message (like UPCsendMessage0) referencing directly to a class, maybe
> calling UPclass(...).
>
> I hope you understood the issue and any help is appretiated.
>
> Thanks in advance.
>
> Best wishes,
> Diego Park

Reply | Threaded
Open this post in threaded view
|

Re: DLL & C Connect

Alejandro F. Reimondo
Diego,
You can interact with a running image through an OLEAutomation interface,
 similar to the interface used to wrap VS services in vs4web
 (the vs4web component is a dll -activeX- implemented in C
 that send events to the smalltalk application, anOLEAutomation
 server; more information at http://www.aleReimondo.com.ar/vs4web ).
To send messages or evaluate code, you can provide an interface
 to send strings to be compiled (slow & easy solution)
 or anothe rmechanism as scripting.
best,
Ale.

> diego park wrote:
> > Hey,
> >
> > I am having problems with DLL & C Connect in VisualWorks 7.4nc. I admit
> > I had spent little time investigating -just read the documentation-, but
> > I want to waste as little as possible time in this (accidental) issue
> > and focus on the main problem.
> >
> > We are working with 3D Robot Soccer Simulator (in particular, version
> > 1.5a) and it expects a DLL to export methods Create, Strategy and
> > Destroy. I am thinking of building a DLL that only forwards messages to
> > VisualWorks to do the actual processing work. We have a DLL that already
> > that this job but it's connecting to VisualSmalltalk, which is somewhat
> > messy to work with.
> >
> > So, suppose I want to send a message to a class --I thought of a class
> > instead of an instance, to avoid dealing with problems raised from GC
> > pointers reallocation, maybe. For the examples I read in the
> > documentation, one possibility is to send a message from Smalltalk with
> > the receiver, and get the class through UPclass(aReceiver) and finally
> > send a message back to Smalltalk with the actual message (say,
> > StrategyInterface>>strategy) . That is, I am only starting a message
> > sequence from Smalltalk to know the receiver's class (memory address?).
> > Is it possible to avoid this first message and refer directly to a
> > Smalltalk class straight from C? Thus, I want to start the message-send
> > sequence fom C (instead of sending a message from Smalltalk, like <C:
> > void foo(_oop self, ...)>), so I was wondering if it's possible to send
> > a message (like UPCsendMessage0) referencing directly to a class, maybe
> > calling UPclass(...).
> >
> > I hope you understood the issue and any help is appretiated.
> >
> > Thanks in advance.
> >
> > Best wishes,
> > Diego Park
>

Reply | Threaded
Open this post in threaded view
|

Re: DLL & C Connect

diego park
In reply to this post by Reinout Heeck-2
thanks for the answers, i'll try both suggestions.
 
beyond that, i overlooked i could register a class, which is probably what i wanted to do.
 
best wishes,
diego
 
2006/5/9, Reinout Heeck <[hidden email]>:
I am not a DLLCC guru, but here's my 2 cents worth:

-VisualWorks can not be wrapped by (or as) a dll yet, so you'll need to
figure out how both VisualWorks and the other side can bind to your dll
while sharing data (and in a thread-safe way).
-Push as much of the nitty gritty into Smalltalk as possible, in your
case I would suggest write your dll such that VisualWorks can register
functions with it that will return classes, send particular messages
etc. It is trivial to pass a block from VisualWorks as a callback into
the dll, the block can do the low-level messaging, iow you shouldn't
need to use UPClass, UPSendMessage etc from your C code, you simply need
to call the *function* that VW passed to your dll at initialization time.
So at init time from Smalltalk you do something like
  yourDll classFoo: (CCallback do: [Foo]);
  yourDll classBar: (CCallback do: [Bar]);
  yourDll sendBaz: (CCallback do: [ :receiver :arg | receiver baz: arg])

Now your C code can simply call a registered classX function to get the
class' oop and immediately follow with a call to a registered sendXX
function passing in the class and possibly other arguments.

I think this yields simple C code as well as decoupling sufficiently to
be able to experiment with different class implementations.


HTH,

Reinout
-------


diego park wrote:

> Hey,
>
> I am having problems with DLL & C Connect in VisualWorks 7.4nc. I admit
> I had spent little time investigating -just read the documentation-, but
> I want to waste as little as possible time in this (accidental) issue
> and focus on the main problem.
>
> We are working with 3D Robot Soccer Simulator (in particular, version
> 1.5a) and it expects a DLL to export methods Create, Strategy and
> Destroy. I am thinking of building a DLL that only forwards messages to
> VisualWorks to do the actual processing work. We have a DLL that already
> that this job but it's connecting to VisualSmalltalk, which is somewhat
> messy to work with.
>
> So, suppose I want to send a message to a class --I thought of a class
> instead of an instance, to avoid dealing with problems raised from GC
> pointers reallocation, maybe. For the examples I read in the
> documentation, one possibility is to send a message from Smalltalk with
> the receiver, and get the class through UPclass(aReceiver) and finally
> send a message back to Smalltalk with the actual message (say,
> StrategyInterface>>strategy) . That is, I am only starting a message
> sequence from Smalltalk to know the receiver's class (memory address?).
> Is it possible to avoid this first message and refer directly to a
> Smalltalk class straight from C? Thus, I want to start the message-send
> sequence fom C (instead of sending a message from Smalltalk, like <C:
> void foo(_oop self, ...)>), so I was wondering if it's possible to send
> a message (like UPCsendMessage0) referencing directly to a class, maybe
> calling UPclass(...).
>
> I hope you understood the issue and any help is appretiated.
>
> Thanks in advance.
>
> Best wishes,
> Diego Park

Diego,
You can interact with a running image through an OLEAutomation interface,
 similar to the interface used to wrap VS services in vs4web
 (the vs4web component is a dll -activeX- implemented in C
 that send events to the smalltalk application, anOLEAutomation
 server; more information at <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.alereimondo.com.ar/vs4web" target="_blank">http://www.aleReimondo.com.ar/vs4web ).
To send messages or evaluate code, you can provide an interface
 to send strings to be compiled (slow & easy solution)
 or anothe rmechanism as scripting.
best,
Ale.