0

I used a sharedvar.dll with Multicharts without any issue, I try with Python 3.10 but get some error:

here my script:

from ctypes import *
#                   DLL     ,           RETURN VALUE ,  FUCTION NAME,   PARAMS
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", int,    "svInit",      string;
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", int,    "svGetInt",    int,string;
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", bool,   "svSetValue",  int,string,double;
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", bool,   "svGetBool",   int,string;
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", string, "svGetString", int,string;
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", double, "svGetDouble", int,string;
#DefineDLLFunc: "C:\Windows\SharedVar-a64.dll", bool,   "svSetString", int,string,string;

#Windows sharedvar server software       https://fx1.net/sharedvar.php#id1

c_lib = "C:\\Windows\\SharedVar-a64.dll"

Symbol = "15"

lib = cdll.LoadLibrary(c_lib)

print(lib)
#load ok


lib.svInit.argtype = [c_wchar_p]
lib.svInit.restype = c_double

#linkID = lib.svInit(Symbol)
linkID = lib.svInit("15")

#lib.svGetDouble.restype = c_int64
lib.svGetDouble.restype = c_int
lib.svGetDouble.argtype = [c_int, c_wchar_p]

ret = lib.svGetDouble(linkID, "PC")
print(ret)
error :

C:\Users\Gilles\PycharmProjects\pythonProject\sockets-python-master\venv\Scripts\python.exe "C:/Users/Gilles/PycharmProjects/pythonProject/sockets-python-master/test shared2.py"

<CDLL 'C:\Windows\SharedVar-a64.dll', handle 7ffa05b60000 at 0x1ac76f42e00>
Traceback (most recent call last):
  File "C:\Users\Gilles\PycharmProjects\pythonProject\sockets-python-master\test shared2.py", line 26, in <module>

    linkID = lib.svInit("15")
OSError: [WinError -532462766] Windows Error 0xe0434352

Process finished with exit code 1
shafee
  • 15,566
  • 3
  • 19
  • 47
gillou
  • 1
  • 1
  • 1
    According to the docs the "a64" of the DLL name refers to **ANSI** 64bit but you define a widechar (unicode) string as argument type. – Michael Butscher Oct 19 '22 at 03:53
  • What are the actual C prototypes? `string` isn’t a C type so `c_wchar_p` could be wrong. The return types of a svInit and svGetDouble are wrong – Mark Tolonen Oct 19 '22 at 04:10
  • ok how to swith to ANSI syntax ? – gillou Oct 19 '22 at 07:08
  • 1
    Duplicate of [\[SO\]: C function called from Python via ctypes returns incorrect value (@CristiFati's answer)](https://stackoverflow.com/a/58611011/4788546). It's *argtype**s***. If it still doesn't work afterwards, then replace *c\_wchar\_p* by *c\_char\_p*. – CristiFati Oct 19 '22 at 15:25
  • @CristiFati \n funcInit.argtypes = [ctypes.c_char_p] #NOT got error linkID = funcInit(Symbol) ctypes.ArgumentError: argument 1: : wrong type #funcInit.argtypes = [ctypes.c_char] #NOT got error linkID = funcInit(Symbol) ctypes.ArgumentError: argument 1: : wrong type #funcInit.argtypes = [ctypes.c_wchar] #NOT got error linkID = funcInit(Symbol) ctypes.ArgumentError: argument 1: : wrong type #funcInit.argtypes = [ctypes.c_wchar_p] #NOT got error linkID = funcInit(Symbol) OSError: [WinError -532462766] Windows Error 0xe0434352 – gillou Oct 22 '22 at 09:57
  • I never mentioned *c\_char* or *c\_wchar*, only their pointer (\*_**\_p**_) variants. If *argtypes* is *c\_char\_p*, then (as the *doc* **clearly** states), you should use *ASCII* strings: `linkID = lib.svInit(b"15")`. Also add the new findings into the question rather than comments. – CristiFati Oct 22 '22 at 12:13

1 Answers1

0

Try replacing line c_lib = "C:\Windows\SharedVar-a64.dll" with c_lib = "C:\Windows\SharedVar-w64.dll"

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 04 '22 at 13:20