Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Python: Общие вопросы > как вызвать __stdcall функцию из dll


Автор: iigor 23.1.2009, 14:05
Код


Код


from ctypes import *
import os.path

path = os.path.join(os.path.dirname(__file__), 'fakedll.dll').replace('\\','/')

a = CDLL(path)

print a
dir(a)

str = create_string_buffer("1"*100)
err = create_string_buffer("errrrrrrror")
ddd = c_int(1)

print a.test2()

print a._test()
#print a.test() # выдаёт туже ошибку!




имеем.
Код



G:\igor\apps\devel\python\stockgate-p\test>python test2.py
<CDLL 'fakedll.dll', handle 10000000 at 9e8fd0>
1
Traceback (most recent call last):
  File "test2.py", line 17, in <module>
    print a._test()
  File "c:\usr\python25\lib\ctypes\__init__.py", line 361, in __getattr__
    func = self.__getitem__(name)
  File "c:\usr\python25\lib\ctypes\__init__.py", line 366, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function '_test' not found
>



dll:

Код

#include <windows.h>


#define TRANS2QUIK_API __declspec (dllexport)


extern "C" {



long TRANS2QUIK_API test2()
{
    return 1;
}


long TRANS2QUIK_API __stdcall test()
{
    return 1;
}



}




Проблема в том, что dll уже имеется и там ничего поменять нельзя конечно.

интересен вывод

Код

G:\igor\apps\devel\python\stockgate-p\test>dumpbin /exports fakedll.dll
Microsoft (R) COFF Binary File Dumper Version 5.00.7022
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.


Dump of file fakedll.dll

File Type: DLL

         Section contains the following Exports for fakedll.dll

                   0 characteristics
            4979A125 time date stamp Fri Jan 23 15:51:17 2009
                0.00 version
                   1 ordinal base
                  2 number of functions
                  2 number of names

            ordinal hint   name

                  2    0   _test@0  (0000101E)
                  1    1   test2  (00001000)

     Summary

        7000 .data
        1000 .idata
        3000 .rdata
        2000 .reloc
       1B000 .text


Автор: iigor 23.1.2009, 14:57
CDLL(path) нужно заменить на WinDLL(path)

всем спасибо))

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)