[Pharo-dev] How to listen for windows messages?

Dimitris Chloupis kilon.alios at gmail.com
Tue Feb 28 07:52:38 EST 2017


> How can I set up a windows message hook in Pharo?
> Please keep in mind I'm very new to programming, but I work from home and
> have lots of time to learn :-)
>

First of all Torsten gave you an excellent answer. If read it once, go
reread it 10 times and bookmark it. Second of all I cannot answer precisely
what code you will need because I have not done this before.

I did have a recent experience with UFFI. Apart from some of the basics of
UFFI that you need to be aware of , everything else is pretty
straightforward.
I did work with shared memory mapped files which is an extremely low level
functionality of an OS, so low level that is included in the OS kernel and
forms the basic of OS memory management. I expected to be insanely hard and
I was suprised how simple it was. It started as a joke (how to make Pharo
controll C++ applications) it turned out into a serious Pharo library
(CPP).

The main reason for this is the fact that UFFI keeps the C syntax almost
intact when it comes to function signatures. But the big catch here is that
you need to be familiar with C and the libraries you are going to use. It
will be super easy to use them from Pharo but the task itself may not.
Pharo maybe be a higher level language but C is not. C is not low level but
still you need to know how to do manual memory management and also OS APIs
tend to be quite technical too.

The general idea is that Pharo will follow the C approach to the letter
even when it comes to manual memory management. So if you do not know C ,
drop anything you do and go learn it NOW.

My advice is to NOT i repeat DO NOT do this in Pharo.

First do this in C.

Why ?

First of all you will find tons of example code online, so all you have to
do is copy paste and modify accordingly.

So getting the code to work is suprisingly easy but understanding the code
and why when you made changes started crashing for no apparent reason is a
lot more difficult.

Second of all Pharo IDE may be awesome but is made to be used with Pharo
not with C libraries. A C debugger and generally a C ide , in case of
windows Visual Studio is free and very efficient will help you deal with
bugs a lot easier.

When a bug happens in Pharo , the IDE practically takes you by the hand and
helps you find it and correct it.

When a bug happens in C code , even C code run from inside Pharo via UFFI
it will crash your C executable or Pharo itself and no error will be
displayed apart from extremely limited information.

However this comparison is unfair because Pharo comes with an IDE , C
usually does not.

But C with Visual Studio or other IDEs will help you get very close to
Pharo experience. Obviously not the same , but quite close none the less.

Generally my approach was to start with prints , printing values and
information to track exactly what went wrong with my C code . Then when
prints became too many I used Visual Studio debugger breakpoints, that stop
execution so you can examine what code is actually executed and fails and
watchpoints which basically keep track of data inside variables so you can
find bugs that are more tricky to find than executing the wrong code.

Also find a C forum and ask question. You wont get much help here because
even though UFFI is very important the vast majority of Pharo coders prefer
to stay away from C coding because C coding is not Pharo coding.

If you figure out how to do this in C it will take you literally minutes to
port it to Pharo , its pretty much the exactly same process and exactly
same code. Well almost.

The process is the same for any C library and C code called from Pharo, the
rest is just techncial documentation which you will find a ton online.
Thats one of the advantages of using a popular language like C.

So go and do this in C and make sure it works in C then try to port it to
Pharo. If Pharo gives you any problems you can always copy paste your code
here, or preferably using an online code snippet service like pastebin or
gist and we will guide you through how to fix your errors since the process
is the same for all C code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20170228/438a20b9/attachment.html>


More information about the Pharo-dev mailing list