[python-win32] Problem with msvcr90.dll

2011-01-31 Thread Tefnet Developers
Hi,

I am developing a msgina replacement.

I am at the point where I have the whole Gina API handled in python (a
dll written in C, calling methods of a python object).

My problem is that somehow my program cannot import pywin32 modules: 


Jan 31 12:12:41 p11 pygina: callproxy.caller:   File 
"c:\teflogon\system_nt.py", line 4, in 
Jan 31 12:12:41 p11 pygina: callproxy.caller: import pywintypes
Jan 31 12:12:41 p11 pygina: callproxy.caller:   File 
"C:\Python26\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
Jan 31 12:12:41 p11 pygina: callproxy.caller: 
__import_pywin32_system_module__("pywintypes", globals())
Jan 31 12:12:41 p11 pygina: callproxy.caller:   File 
"C:\Python26\lib\site-packages\win32\lib\pywintypes.py", line 64, in 
__import_pywin32_system_module__
Jan 31 12:12:41 p11 pygina: callproxy.caller: import _win32sysloader
Jan 31 12:12:41 p11 pygina: callproxy.caller: ImportError: DLL load failed: The 
specified module could not be found


I did a check and replaced the failing method with execution of
python.exe running the same code: 


if __name__ != '__main__':
subprocess.call(
[r'c:\python26\python.exe', r'c:\teflogon\tefgina.py', 
pMessage],
)


And pywintypes gets imported fine there.

My dll is built using mingw, like this:
i586-mingw32msvc-gcc -L./lib -shared -Wl,--kill-at pygina.o -o
pygina.dll -lpython26

I thought it had something to do with msvcr90.dll, so I've tried the
following:

1. Adding -lmsvcr90 at the end of the linking command
2. Including a manifest in the dll:


$ cat pygina.dll.manifest

  

  

  

  
  

  

  

$ grep manifest pygina.rc.in
2 RT_MANIFEST pygina.dll.manifest

$


But it did not change a thing.

So the question is - why can python.exe load pywin32 modules and my dll
cannot?

I have been stuck with this for a couple of days now and any pointers
would be great :).


Thanks,
Filip Zyzniewski
Tefnet 
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem with msvcr90.dll

2011-02-01 Thread Tefnet Developers
Dnia 2011-02-01, wto o godzinie 10:44 +1100, Mark Hammond pisze:
> This stuff is painful and poorly documented.  Is it possible the code 
> which triggers the failing import is on a different thread than the one 
> which loaded Python? 

I have added a little thread id reporting function:

static void logThread(const char *where) {
FILE *log = fopen(LOGFILE, "a");
fprintf(log, "pygina thread id @ %s: %d\n", where,
GetCurrentThreadId());
fclose(log);
}

I've put it before each method call and before Py_Initialize, and it all
happens in one thread:

pygina thread id @ WlxNegotiate: 612
pygina thread id @ Py_Initialize: 612
pygina thread id @ WlxInitialize: 612
pygina thread id @ WlxDisplayStatusMessage: 612
pygina thread id @ WlxRemoveStatusMessage: 612
pygina thread id @ WlxDisplaySASNotice: 612
pygina thread id @ WlxRemoveStatusMessage: 612
pygina thread id @ WlxLoggedOutSAS: 612

Should I need to do any linking against msvcr90 if python26.dll is
already linked against it and I am linked to python26.dll?

Thanks,
Filip Zyzniewski
Tefnet

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem with msvcr90.dll

2011-02-01 Thread Tefnet Developers
Dnia 2011-02-01, wto o godzinie 10:44 +1100, Mark Hammond pisze:
> This stuff is painful and poorly documented.  Is it possible the code 
> which triggers the failing import is on a different thread than the one 
> which loaded Python?  If so, I suspect the magic done by Python in 
> dl_nt.c may not be kicking in, which is supposed to ensure all python 
> modules are loaded using the "activation context" defined by pythonxx.dll.

The smallest piece of program that shows the problem:

$ cat pytest.c
#include 


int main(void) {
Py_Initialize();
PyRun_SimpleString(
"import traceback \n"
"try:\n"
"   import pywintypes\n"
"except:\n"
"   traceback.print_exc()\n"
);
}

$ make pytest.exe
i586-mingw32msvc-gcc -I./include -I./include/python -Wall -pedantic
-std=c99-c -o pytest.o pytest.c

i586-mingw32msvc-gcc -L./lib -o pytest.exe pytest.o -lmingw32 -lpython26
rm pytest.o

$

The output looks like this:

C:\>pytest
Traceback (most recent call last):
  File "", line 3, in 
  File "C:\Python26\lib\site-packages\win32\lib\pywintypes.py", line
124, in 
__import_pywin32_system_module__("pywintypes", globals())
  File "C:\Python26\lib\site-packages\win32\lib\pywintypes.py", line 64,
in __import_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found

C:\>


It loads fine if I add -lmsvcr90 to the linking flags, but I think it
should not be necessary, right?

bye,
Filip Zyzniewski
Tefnet

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Problem with win32print.SetPrinter

2011-02-28 Thread Tefnet Developers
Hi,

I am adding some printers connection as a user with
win32print.AddPrinterConnection().

Afterwards I want to set paper size to A4 (I have no idea why Polish
Windows XP sets it to Letter by default) with this example code:

==
import win32print
import win32con
import win32gui
import pywintypes

printer = r'\\drukarki\kp01'

handle = win32print.OpenPrinter(printer, {'DesiredAccess':
win32print.PRINTER_ACCESS_USE})

devmodeSize=win32print.DocumentProperties(0, handle, printer, None,
None, 0)
devmode = pywintypes.DEVMODEType(devmodeSize -
pywintypes.DEVMODEType().Size)
win32print.DocumentProperties(0, handle, printer, devmode, devmode,
win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER)

print 'FormName before: %s' % devmode.FormName
print 'PaperSize before: %s' % devmode.PaperSize

devmode.FormName = "A4"
devmode.PaperSize = win32con.DMPAPER_A4
devmode.Fields = devmode.Fields | win32con.DM_FORMNAME |
win32con.DM_PAPERSIZE

print 'FormName set: %s' % devmode.FormName
print 'PaperSize set: %s' % devmode.PaperSize

info = win32print.GetPrinter(handle, 9)
info["pDevMode"] = devmode
win32print.SetPrinter(handle, 9, info, 0)

devmodeSize=win32print.DocumentProperties(0, handle, printer, None,
None, 0)
devmode = pywintypes.DEVMODEType(devmodeSize -
pywintypes.DEVMODEType().Size)
win32print.DocumentProperties(0, handle, printer, devmode, devmode,
win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER)

print 'FormName after: %s' % devmode.FormName
print 'PaperSize after: %s' % devmode.PaperSize

win32print.ClosePrinter(handle)

win32gui.SendMessageTimeout(win32con.HWND_BROADCAST,
win32con.WM_DEVMODECHANGE, 0, 0, 0, 2000)
==

The output looks like this:
==
FormName before: A4
PaperSize before: 1
FormName set: A4
PaperSize set: 9
FormName after: A4
PaperSize after: 1
==

So, as you can see - FormName changes, but PaperSize does not.
Am I doing something wrong here? I've spent a lot of time trying to
solve it, yet came up with nothing.

Do you have any suggestions?

Thanks,
Filip Zyzniewski
Tefnet

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem with win32print.SetPrinter

2011-03-01 Thread Tefnet Developers
Dnia 2011-02-28, pon o godzinie 19:11 -0500, Roger Upole pisze:
> I think this is dependent on the printer driver.
> Some use the paper size defined by the the form,
> and others use the PaperSize member.

The driver used is the generic postscript driver (MS Publisher
Imagesetter) provided with Windows.

My problem is that changing paper size in the default printer
preferences UI changes both members of devmode.

Changing the way I do it (as shown before) does not change the paper
size in preferences UI - and that's exactly what I need to change.

I guess that if both fields are affected by the UI then I should also
change both to achieve the desired effect, right?

bye,
Filip Zyzniewski
Tefnet


___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32