1

I'm try use SIP wrapper C++ for Python, but it's fail.How can I solov it?

My softwares' version:
- QT 5.9.1 MSVC2015
- PYQT 5.9.1
- PYTHON 3.6.4
- SIP 4.19.8

//foo.h

#ifndef FOO_H
#define FOO_H

#if defined(FOO_LIBRARY)
    #define FOOSHARED_EXPORT __declspec(dllexport)
#else
    #define FOOSHARED_EXPORT __declspec(dllimport)
#endif
FOOSHARED_EXPORT int len(const char* str);
#endif //FOO_H

//foo.cpp

#include <string.h>
#include<foo.h>

int len(const char* str)
{
    return strlen(str);
}

//foo.sip

%Module(name=foo)  
%UnitCode  
    #include <foo.h>  
%End  
int len(const char* str);  

I'm used vs2015 craet foo.dll , foo.lib and used nmake(install) foo.pyd.

I'm try import foo, it's OK.

Hoever, I'm used foo.len("123"), python told me error:

len(): argument 1 has unexpected type 'str'  

I don't know why..

-------------------------- update on 2018.04.03 ---------------------------

Today, I'm try foo.len("123".encode('gb2312')), it's right!
But I don't know why..
I'm try compile foo.dll , foo.lib by utf8, but the same of the error.

JH Lin
  • 11
  • 2

0 Answers0