Passing full LPCSTR to C ++ dll from python text

I have a simple C ++ dll that calls MessageBox to display text

#include <Windows.h>

#define LIBDLL extern "C" __declspec(dllexport)

LIBDLL void Display(LPCTSTR lpInput) {
    MessageBox(0, lpInput, 0, 0);
}

bool __stdcall DllMain(void* hModule, unsigned long dwReason, void* lpReserved) {
switch (dwReason)
{

case 1:
    break;
case 0:
    break;

case 2:
    break;

case 3:
    break;

}

return true;
}

      

And the Python code only passes the Display string to the DLL, it looks like

import ctypes
sampledll = ctypes.WinDLL('SampleDll.dll')
sampledll.Display('Some Text')

      

And it only displays the first letter even if I use std :: cout

MessageBox output

How do I display all the text that I have passed to it?

+3


source to share


1 answer


Finally, fix this. It turns out that I have to encode the text before passing it to the dll.

So instead of this

sampledll.Display('Some Text')

      



It should be done like this:

sampledll.Display('Some Text'.encode('utf-8))

      

0


source







All Articles