c++ - ctypes passing C string to Python, ValueError: invalid string pointer -


i'm trying pass const char * c code python via ctypes. here code:

.h file:

extern "c" {     _declspec(dllexport)         const char * return_string(); } 

.cpp file:

const char * return_string() {     const char* test = "test";     return test; } 

python code:

a = lib.return_string(); print("a =",a)  b = c_char_p(a).value print(b) 

result:

> = -1781171860 traceback (most recent call last):   file > "c:\users\krzys\desktop\test\pythontest.py", > line 23, in <module> >     b = c_char_p(a).value valueerror: invalid string pointer 0xffffffff95d5796c [finished in 0.1s] 

what causes problem?

is related memory management or wrong approach of getting c string?


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -