CogVM arguments in Win32

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

CogVM arguments in Win32

Bernat Romagosa
Hi list!

I've never used Pharo on Windows before, but we're starting to package a multi-platform app right now and I've just found out command line arguments don't work like I thought they would. I need to run the image headless, so I figured:

bin-win32\Pharo -headless shared\Pharo2.0.image

Would do the trick, but it's not working.

Pharo /? doesn't give any hints either, and I can't seem to find the docs for the Windows VM anywhere.

Does anybody know where I can find a Win32 VM reference?

Thanks!

--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Bernat Romagosa
Ok, I see Pharo -help brings up a window with command line options, but -headless is still firing up the GUI... any ideas?


2013/10/29 Bernat Romagosa <[hidden email]>
Hi list!

I've never used Pharo on Windows before, but we're starting to package a multi-platform app right now and I've just found out command line arguments don't work like I thought they would. I need to run the image headless, so I figured:

bin-win32\Pharo -headless shared\Pharo2.0.image

Would do the trick, but it's not working.

Pharo /? doesn't give any hints either, and I can't seem to find the docs for the Windows VM anywhere.

Does anybody know where I can find a Win32 VM reference?

Thanks!

--
Bernat Romagosa.



--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Igor Stasenko
try double-dashed option:

from vm/sqWin32Intel.c :
  
 else if (!strcmp(argv[0], "--headless")) { fHeadlessImage = true; return 1; }

this is really a mess with VM options handled differently on different OSes.



On 29 October 2013 11:14, Bernat Romagosa <[hidden email]> wrote:
Ok, I see Pharo -help brings up a window with command line options, but -headless is still firing up the GUI... any ideas?


2013/10/29 Bernat Romagosa <[hidden email]>
Hi list!

I've never used Pharo on Windows before, but we're starting to package a multi-platform app right now and I've just found out command line arguments don't work like I thought they would. I need to run the image headless, so I figured:

bin-win32\Pharo -headless shared\Pharo2.0.image

Would do the trick, but it's not working.

Pharo /? doesn't give any hints either, and I can't seem to find the docs for the Windows VM anywhere.

Does anybody know where I can find a Win32 VM reference?

Thanks!

--
Bernat Romagosa.



--
Bernat Romagosa.



--
Best regards,
Igor Stasenko.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

EstebanLM
In reply to this post by Bernat Romagosa
AFAIK you can't. 
no matter what you do, it stills shows a pharo in the trial. 

I remember once I hid the fact that I had the app running there by replacing the world with an "administrative morph" (just as other server apps do). 
It was not terrible cool, but it worked. 

Esteban

On Oct 29, 2013, at 7:14 AM, Bernat Romagosa <[hidden email]> wrote:

Ok, I see Pharo -help brings up a window with command line options, but -headless is still firing up the GUI... any ideas?


2013/10/29 Bernat Romagosa <[hidden email]>
Hi list!

I've never used Pharo on Windows before, but we're starting to package a multi-platform app right now and I've just found out command line arguments don't work like I thought they would. I need to run the image headless, so I figured:

bin-win32\Pharo -headless shared\Pharo2.0.image

Would do the trick, but it's not working.

Pharo /? doesn't give any hints either, and I can't seem to find the docs for the Windows VM anywhere.

Does anybody know where I can find a Win32 VM reference?

Thanks!

--
Bernat Romagosa.



--
Bernat Romagosa.

Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Bernat Romagosa
indeed, --headless does "work" but the image just dies after executing it... :(

I guess some FFI research to minimize the app to tray is in place.

Thanks!


2013/10/29 Esteban Lorenzano <[hidden email]>
AFAIK you can't. 
no matter what you do, it stills shows a pharo in the trial. 

I remember once I hid the fact that I had the app running there by replacing the world with an "administrative morph" (just as other server apps do). 
It was not terrible cool, but it worked. 

Esteban

On Oct 29, 2013, at 7:14 AM, Bernat Romagosa <[hidden email]> wrote:

Ok, I see Pharo -help brings up a window with command line options, but -headless is still firing up the GUI... any ideas?


2013/10/29 Bernat Romagosa <[hidden email]>
Hi list!

I've never used Pharo on Windows before, but we're starting to package a multi-platform app right now and I've just found out command line arguments don't work like I thought they would. I need to run the image headless, so I figured:

bin-win32\Pharo -headless shared\Pharo2.0.image

Would do the trick, but it's not working.

Pharo /? doesn't give any hints either, and I can't seem to find the docs for the Windows VM anywhere.

Does anybody know where I can find a Win32 VM reference?

Thanks!

--
Bernat Romagosa.



--
Bernat Romagosa.




--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Bernat Romagosa
In this direction, I'm trying to call a function in the shell32.dll lib that apparently should let you minimize an app to the system tray, but I'm not having much luck... I guess I don't really understand what am I exactly doing.

BOOL Shell_NotifyIcon(
  _In_  DWORD dwMessage,
  _In_  PNOTIFYICONDATA lpdata
);

So, I tried to translate this into Pharo as:

MyClass >> minimizeToTray: dwMessage data: lpData

  <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module: 'shell32.dll'>

But it won't let me save the method, reporting it's expecting an argument before PNOTIFYICONDATA.

I realize PNOTIFYICONDATA is not a primitive type, but I just don't know how to handle it... :(

Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Igor Stasenko
You can try something like this:

| handle window |

handle := NativeBoost forCurrentPlatform squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or

window setWindowText: 'im a main window blablabla'.

:)

i didn't tested it since its been implemented, but i think it should work.



On 30 October 2013 11:20, Bernat Romagosa <[hidden email]> wrote:
In this direction, I'm trying to call a function in the shell32.dll lib that apparently should let you minimize an app to the system tray, but I'm not having much luck... I guess I don't really understand what am I exactly doing.

BOOL Shell_NotifyIcon(
  _In_  DWORD dwMessage,
  _In_  PNOTIFYICONDATA lpdata
);

So, I tried to translate this into Pharo as:

MyClass >> minimizeToTray: dwMessage data: lpData

  <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module: 'shell32.dll'>

But it won't let me save the method, reporting it's expecting an argument before PNOTIFYICONDATA.

I realize PNOTIFYICONDATA is not a primitive type, but I just don't know how to handle it... :(




--
Best regards,
Igor Stasenko.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

philippeback
Well, this should rather be:

handle :=NativeBoostWin32 squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or 

window setWindowText: 'im a main window blablabla'.

Phil


On Thu, Oct 31, 2013 at 10:03 PM, Igor Stasenko <[hidden email]> wrote:
You can try something like this:

| handle window |

handle := NativeBoost forCurrentPlatform squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or

window setWindowText: 'im a main window blablabla'.

:)

i didn't tested it since its been implemented, but i think it should work.



On 30 October 2013 11:20, Bernat Romagosa <[hidden email]> wrote:
In this direction, I'm trying to call a function in the shell32.dll lib that apparently should let you minimize an app to the system tray, but I'm not having much luck... I guess I don't really understand what am I exactly doing.

BOOL Shell_NotifyIcon(
  _In_  DWORD dwMessage,
  _In_  PNOTIFYICONDATA lpdata
);

So, I tried to translate this into Pharo as:

MyClass >> minimizeToTray: dwMessage data: lpData

  <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module: 'shell32.dll'>

But it won't let me save the method, reporting it's expecting an argument before PNOTIFYICONDATA.

I realize PNOTIFYICONDATA is not a primitive type, but I just don't know how to handle it... :(




--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Bernat Romagosa
Hi!

Thanks Igor, that kinda worked! Pharo hides, but comes back after half a second or so. I'll keep digging, thanks! :)


2013/11/1 [hidden email] <[hidden email]>
Well, this should rather be:

handle :=NativeBoostWin32 squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or 

window setWindowText: 'im a main window blablabla'.

Phil


On Thu, Oct 31, 2013 at 10:03 PM, Igor Stasenko <[hidden email]> wrote:
You can try something like this:

| handle window |

handle := NativeBoost forCurrentPlatform squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or

window setWindowText: 'im a main window blablabla'.

:)

i didn't tested it since its been implemented, but i think it should work.



On 30 October 2013 11:20, Bernat Romagosa <[hidden email]> wrote:
In this direction, I'm trying to call a function in the shell32.dll lib that apparently should let you minimize an app to the system tray, but I'm not having much luck... I guess I don't really understand what am I exactly doing.

BOOL Shell_NotifyIcon(
  _In_  DWORD dwMessage,
  _In_  PNOTIFYICONDATA lpdata
);

So, I tried to translate this into Pharo as:

MyClass >> minimizeToTray: dwMessage data: lpData

  <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module: 'shell32.dll'>

But it won't let me save the method, reporting it's expecting an argument before PNOTIFYICONDATA.

I realize PNOTIFYICONDATA is not a primitive type, but I just don't know how to handle it... :(




--
Best regards,
Igor Stasenko.




--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Bernat Romagosa
Hi list,

I made some progress but I'm still a bit lost here.

I managed to get Pharo to be headless in Win32, by hiding the window via NB as Igor suggested, plus suspending the UI process (UIManager default uiProcess suspend), which was the cause for the window to show up again after a fraction of a second, because of the refresh interval.

However, now I can only close Pharo by killing the process manually, which is not very nice for the end user. So I figured I'd try to add an icon to the system tray with a single context menu entry for closing Pharo.

This is what I'm doing, taken from MSDN:

NBWin32Shell >> shellNotifyIcon: lpdata dwMessage: dwMessage

<primitive: #primitiveNativeCall module: #NativeBoostPlugin>

^ self nbCall: #(bool Shell_NotifyIcon(
  DWORD dwMessage,
  PNOTIFYICONDATA lpdata
)) module: #shell32

dwMessage is just a 0 (flag to create a tray icon), but lpdata needs to be a pointer to a struct of this form:

typedef struct _NOTIFYICONDATA {
  DWORD cbSize;
  HWND  hWnd;
  UINT  uID;
  UINT  uFlags;
  UINT  uCallbackMessage;
  HICON hIcon;
  TCHAR szTip[64];
  DWORD dwState;
  DWORD dwStateMask;
  TCHAR szInfo[256];
  union {
    UINT uTimeout;
    UINT uVersion;
  };
  TCHAR szInfoTitle[64];
  DWORD dwInfoFlags;
  GUID  guidItem;
  HICON hBalloonIcon;
} NOTIFYICONDATA, *PNOTIFYICONDATA;

So, my question is: how do I translate this into NB code? How does one define a struct and then pass its pointer to a function in NativeBoost?

Thanks a lot for your help, I'm getting closer :)

Bernat.

p.s. Could the Windows API be any more convoluted and dev-unfriendly in any possible sense?



2013/11/4 Bernat Romagosa <[hidden email]>
Hi!

Thanks Igor, that kinda worked! Pharo hides, but comes back after half a second or so. I'll keep digging, thanks! :)


2013/11/1 [hidden email] <[hidden email]>

Well, this should rather be:

handle :=NativeBoostWin32 squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or 

window setWindowText: 'im a main window blablabla'.

Phil


On Thu, Oct 31, 2013 at 10:03 PM, Igor Stasenko <[hidden email]> wrote:
You can try something like this:

| handle window |

handle := NativeBoost forCurrentPlatform squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or

window setWindowText: 'im a main window blablabla'.

:)

i didn't tested it since its been implemented, but i think it should work.



On 30 October 2013 11:20, Bernat Romagosa <[hidden email]> wrote:
In this direction, I'm trying to call a function in the shell32.dll lib that apparently should let you minimize an app to the system tray, but I'm not having much luck... I guess I don't really understand what am I exactly doing.

BOOL Shell_NotifyIcon(
  _In_  DWORD dwMessage,
  _In_  PNOTIFYICONDATA lpdata
);

So, I tried to translate this into Pharo as:

MyClass >> minimizeToTray: dwMessage data: lpData

  <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module: 'shell32.dll'>

But it won't let me save the method, reporting it's expecting an argument before PNOTIFYICONDATA.

I realize PNOTIFYICONDATA is not a primitive type, but I just don't know how to handle it... :(




--
Best regards,
Igor Stasenko.




--
Bernat Romagosa.



--
Bernat Romagosa.
Reply | Threaded
Open this post in threaded view
|

Re: CogVM arguments in Win32

Igor Stasenko



On 13 November 2013 10:25, Bernat Romagosa <[hidden email]> wrote:
Hi list,

I made some progress but I'm still a bit lost here.

I managed to get Pharo to be headless in Win32, by hiding the window via NB as Igor suggested, plus suspending the UI process (UIManager default uiProcess suspend), which was the cause for the window to show up again after a fraction of a second, because of the refresh interval.

However, now I can only close Pharo by killing the process manually, which is not very nice for the end user. So I figured I'd try to add an icon to the system tray with a single context menu entry for closing Pharo.

This is what I'm doing, taken from MSDN:

NBWin32Shell >> shellNotifyIcon: lpdata dwMessage: dwMessage

<primitive: #primitiveNativeCall module: #NativeBoostPlugin>

^ self nbCall: #(bool Shell_NotifyIcon(
  DWORD dwMessage,
  PNOTIFYICONDATA lpdata
)) module: #shell32

dwMessage is just a 0 (flag to create a tray icon), but lpdata needs to be a pointer to a struct of this form:

typedef struct _NOTIFYICONDATA {
  DWORD cbSize;
  HWND  hWnd;
  UINT  uID;
  UINT  uFlags;
  UINT  uCallbackMessage;
  HICON hIcon;
  TCHAR szTip[64];
  DWORD dwState;
  DWORD dwStateMask;
  TCHAR szInfo[256];
  union {
    UINT uTimeout;
    UINT uVersion;
  };
  TCHAR szInfoTitle[64];
  DWORD dwInfoFlags;
  GUID  guidItem;
  HICON hBalloonIcon;
} NOTIFYICONDATA, *PNOTIFYICONDATA;

So, my question is: how do I translate this into NB code? How does one define a struct and then pass its pointer to a function in NativeBoost?

 
This is easy. Just make a subclass of NBExternalStructure,
define its fields in #fieldsDesc method (see example subclass).
Create it using #new, or #externalNew depending if structure should be non-moving in memory for the rest of its life (but i think its needed only at the moment of call, so #new should work),
fill it with proper values, and then pass it to that function. Just make sure
that argument type PNOTIFYICONDATA changed to class name of your
structure in function signature.
 
Also, note that there is two Shell_NotifyIcon functions under the hood:

Shell_NotifyIconA
Shell_NotifyIconW

the 'A' stands for 'ascii',
and 'W' stands for 'wide',
this is how windows manages strings and characters/unicode.

For 'A' functions TCHAR == char (1byte)
for 'W' functions TCHAR == unsigned short (2bytes)

that means the definition and size of PNOTIFYICONDATA is different
depending on what function you going to be using.

Thanks a lot for your help, I'm getting closer :)

Bernat.

p.s. Could the Windows API be any more convoluted and dev-unfriendly in any possible sense?

hehe.. this is a typical for everything in windows: many, even basic things
require passing and filling various structures with many different fields,
and you may find that to initialize fields of one structure, you often need
to create another one and initialize it first :)





2013/11/4 Bernat Romagosa <[hidden email]>
Hi!

Thanks Igor, that kinda worked! Pharo hides, but comes back after half a second or so. I'll keep digging, thanks! :)


2013/11/1 [hidden email] <[hidden email]>

Well, this should rather be:

handle :=NativeBoostWin32 squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or 

window setWindowText: 'im a main window blablabla'.

Phil


On Thu, Oct 31, 2013 at 10:03 PM, Igor Stasenko <[hidden email]> wrote:
You can try something like this:

| handle window |

handle := NativeBoost forCurrentPlatform squeakWindowHandle.
window := NBWin32Window new value: handle; yourself.
window hide.

or

window setWindowText: 'im a main window blablabla'.

:)

i didn't tested it since its been implemented, but i think it should work.



On 30 October 2013 11:20, Bernat Romagosa <[hidden email]> wrote:
In this direction, I'm trying to call a function in the shell32.dll lib that apparently should let you minimize an app to the system tray, but I'm not having much luck... I guess I don't really understand what am I exactly doing.

BOOL Shell_NotifyIcon(
  _In_  DWORD dwMessage,
  _In_  PNOTIFYICONDATA lpdata
);

So, I tried to translate this into Pharo as:

MyClass >> minimizeToTray: dwMessage data: lpData

  <apicall: bool 'Shell_NotifyIcon' (dword PNOTIFYICONDATA) module: 'shell32.dll'>

But it won't let me save the method, reporting it's expecting an argument before PNOTIFYICONDATA.

I realize PNOTIFYICONDATA is not a primitive type, but I just don't know how to handle it... :(




--
Best regards,
Igor Stasenko.




--
Bernat Romagosa.



--
Bernat Romagosa.



--
Best regards,
Igor Stasenko.