[python-win32] Python interpreter crashes after trying to callback a python function with PyObject_CallObject from a dll

2005-08-10 Thread Oleg Novychny

Hello guys, I’m still implementing my callback to python from my dll and the python interpreter crashes…
I have no idea atm why…

I use the calldll module for calling my c++-dll from my module calldllsound.py:

import calldll
import struct
class CallSoundDLL:
def __init__(self, library):
  self.library = library
  …

 def myGetResults(a):
  print a #just for debugging
calldll.call_foreign_function (self.addrGet,'ll','i',(self.ulHz.address(), self.dNoise.address(), self.bAudio.address(),self.bCrackFlag.address(), self.dSNR.address(), self.bBeep.address()))
  
 def mySetCallback(self):
  calldll.call_foreign_function (self.addrCall,'O','',(self.myGetResults,))

 def start(self):
  # -
  # Get the handle of the dll and the address of the function
  # -
  #Get the handle of the Dll
  handle = calldll.load_library (self.library)
 
  #Get the address of the functions
  self.addrStart = calldll.get_proc_address (handle, 'StartProcessing')
  self.addrEnd = calldll.get_proc_address (handle, 'EndProcessing')
  self.addrGet = calldll.get_proc_address (handle, 'GetResults')
  self.addrCall = calldll.get_proc_address (handle, 'my_set_callback')
 
  # -
  # Initialization
  # -
  self.ulHz = calldll.membuf(4) #unsigned long*
  self.dNoise = calldll.membuf(8) #double*
  self.bAudio = calldll.membuf(4) #int* 
  self.bCrackFlag = calldll.membuf(4) #int* 
  self.dSNR = calldll.membuf(8) #double* 
  self.bBeep = calldll.membuf(4) #int* 
   
  # -
  # Function calling
  # -
  args = (1,1,1,1,1,1000)
  calldll.call_foreign_function (self.addrStart,'ik','i',args)

So I’m starting my dll on such a way:
 import calldllsound
 obj = calldllsound.CallSoundDLL("soundproclib.dll")
 obj.start()
It works without any problems.

But after the following command crashes the python interpreter...:

 obj.mySetCallback()

Here is my_set_callback function from my dll, which have to be called in the python function mySetCallback:

static PyObject *my_callback = NULL;
PyMODINIT_FUNC my_set_callback(PyObject *args)
{
  PyObject *temp = args;
  Py_XINCREF(temp); /* Add a reference to new callback */
  Py_XDECREF(my_callback); /* Dispose of previous callback */
  my_callback = temp; /* Remember new callback */
  Py_INCREF(Py_None);
 
bPyCallBackFlag = true;
};

and here is the part of my code from the same c++-file where I’m trying to call my python-function myGetResults:

…
if (bPyCallBackFlag)
{
 /* Time to call the callback */
 ppyobjArgList = Py_BuildValue("(i)",123); //just for debugging
// Here crashes the python interpreter, I found it out with 
// error logging:
ppyobjResult = PyObject_CallObject(my_callback, ppyobjArgList);
 Py_DECREF(ppyobjResult);
}
…

Have anybody any idea why it doesn’t work?
Thank you very muchOleg
		Gesendet von Yahoo! Mail - Jetzt mit 1GB kostenlosem Speicher___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] build list of all tasks like Alt-TAB box

2005-08-10 Thread Tim Roberts
On Tue, 09 Aug 2005 09:17:24 -0400, Benjamin Rutt [EMAIL PROTECTED] wrote:

Benjamin Rutt [EMAIL PROTECTED] writes:
  


So, you're from that OTHER OSU?  (From an Oregon State University 
alumnus...)

-
from win32gui import *
from win32con import *

gwl_style = GWL_STYLE

def windowEnumerationHandler(hwnd, resultList):
'''Pass to win32gui.EnumWindows() to generate list of window handle, 
 window\
 text tuples.'''
if IsWindowVisible(hwnd):
val = GetWindowLong(hwnd, gwl_style)
if val  WS_VISIBLE:
if not val  WS_CHILD:
if not val  WS_EX_TOOLWINDOW:
if val  WS_EX_CONTROLPARENT:
val = GetWindowLong(hwnd, gwl_style)
txt = GetWindowText(hwnd)
resultList.append((hwnd, txt))

windows = []
EnumChildWindows(GetDesktopWindow(), windowEnumerationHandler, windows)
for w in windows:
print %10s %s % (w[0], w[1])
-

Does anyone happen to know why if the window handle is not an
WS_EX_TOOLWINDOW and is an WS_EX_CONTROLPARENT, then it is one of the
taskbar programs?  Thanks,
  


Google is your friend.  WS_EX_TOOLWINDOW is used to create floating 
toolbars, which can exist outside of the parent app.  You don't want 
those showing up as main windows.  WS_EX_CONTROLPARENT essentially says 
this window contains other controls.  Getting rid of this probably 
gets rid of text-only windows, like tooltips and balloon help.

The spyxx.exe tool can be used to poke around the window list to find 
these things.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Python, Com and SafeArrays

2005-08-10 Thread pylist
Hello List,

I've encountered a problem when trying to use Com in some instances. There is a
method on a Com object called getData() which takes in 4 paramaters ... all
pointers ... and fills them with data. I'm currently using pointer() in ctypes 
on
the four args as they go in (like getData(pointer(one), pointer(two))) but 
am
getting the following error:

$ c:/Python24/python codeshare/comwork.py
Traceback (most recent call last):
  File codeshare/comwork.py, line 96, in ?
t.proccessFiles()
  File codeshare/comwork.py, line 42, in proccessFiles
self.proccessDir(root, dirs)
  File codeshare/comwork.py, line 68, in proccessDir
self.optix.GetFolderItemId(1, pt, ph, po, pr)
  File COMObject Tentix.Application, line 2, in GetFolderItemId
TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer
object.

All help is greatly appreciated,
Steve


___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] build list of all tasks like Alt-TAB box

2005-08-10 Thread Benjamin Rutt
Tim Roberts [EMAIL PROTECTED] writes:

 So, you're from that OTHER OSU?  (From an Oregon State University 
 alumnus...)

and, don't forget about that other other OSU, Oklahoma State.  :-)

 Google is your friend.  WS_EX_TOOLWINDOW is used to create floating 
 toolbars, which can exist outside of the parent app.  You don't want 
 those showing up as main windows.  WS_EX_CONTROLPARENT essentially says 
 this window contains other controls.  Getting rid of this probably 
 gets rid of text-only windows, like tooltips and balloon help.

thanks for the explanation.  I of course I did google for these
things, but found the explanations puzzling; not coming from a Windows
background, I figured there was some hidden knowledge that I could
pick up from this group; the WS_EX_TOOLWINDOW one sort of makes sense,
but I did not see why being a window that contains other controls
should exclude a window from the alt-TAB list; after all, for example,
Web browsers contain other controls, such as text boxes, etc.

 The spyxx.exe tool can be used to poke around the window list to
find these things.

looks like that is not a free tool, apparently bundled with Microsoft
Visual C++, so I guess I can not try that for now.
-- 
Benjamin Rutt

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python interpreter crashes after trying to callbacka python function with PyObject_CallObject from a dll

2005-08-10 Thread Mark Hammond
 static PyObject *my_callback = NULL;
 PyMODINIT_FUNC my_set_callback(PyObject *args)
 {
   PyObject *temp = args;
   Py_XINCREF(temp); /* Add a reference to new callback */
  Py_XDECREF(my_callback);  /* Dispose of previous callback */
  my_callback = temp;   /* Remember new callback */
 Py_INCREF(Py_None);

 bPyCallBackFlag = true;
 };

That looks suspect:
* PyMODINIT_FUNC is probably not what you want - this is not a module init
function.
* The first arg is always self, with args being a second arg.
* You Py_INCREF(Py_None), but don't return it.  I'm surprised that compiles.

Let's say args was NULL (as it probably will be - recall it is supposed to
be self, which generally *will* be NULL.  It should be obvious how that
would crash your code.

Also, note that even if you get the correct args pointer to that function,
it will be a tuple.  Hence all code you will find uses PyArg_ParseTuple to
get the individual items out.  Your callback will be the first item in the
tuple.

 ppyobjResult = PyObject_CallObject(my_callback, ppyobjArgList);

This will fail for that reason - my_callback will *not* be a callable
object.

I don't think either of the mailing lists you have sent this to are
appropriate - the problems are not releated to win32, not are they related
to C++.  You really just need to look over the documentation on writing
extension modules.

Mark.

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python, Com and SafeArrays

2005-08-10 Thread Mark Hammond
 I've encountered a problem when trying to use Com in some
 instances. There is a
 method on a Com object called getData() which takes in 4
 paramaters ... all
 pointers ... and fills them with data. I'm currently using
 pointer() in ctypes on
 the four args as they go in (like getData(pointer(one),
 pointer(two))) but am
 getting the following error:

Assuming you are using win32com, you do not need to explicitly pass pointers
around.  You may need to run makepy for the COM object (the simplest way
is to use win32com.client.gencache.EnsureDispatch instead of a simple
win32com.client.Dispatch).  If the params are all out (rather than in-out)
you should not need to supply them at all, but the function will return them
when you make the call.

Mark

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32