Unicode plugin in C++Builder

jmiller1
2013-03-11
2013-04-07
  • jmiller1
    jmiller1
    2013-03-11

    Hello,

    I tried writing my first plugin in C++Builder (6/XE2) for NP++ but it keeps displaying the error, that the DLL is not unicode. I tried to set "UNICODE" in Project > Options > Path/Conditions; set "#define UNICODE" manually; even removed the compiler definitions "#ifdef UNICODE"; set "native code for MBCS" and "VC++" compatibility in Project > Options > C++ Compiler > Compatibility. But nothing worked and NP++ still complains that the DLL is ANSI.

    By default C++Builder (XE2) uses this main function decleration:

    int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
    

    But I tried also (with and without 'extern "C"'):

    BOOL APIENTRY DllMain(HANDLE hModule, DWORD reasonForCall, LPVOID lpReserved)
    

    I found some Delphi templates here (https://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Plugin_Development) and they compile nice and NP++ links the DLL without any problem! But why can't it link DLLs build with C++Builder? I would greatly appreciate any help. Thanks.

     
  • jmiller1
    jmiller1
    2013-03-14

    Found the problem: C++ name mangling caused by my compiler. But now I get an error message:

    Exception On WM_CREATE
    Unknown exception

    Can you help me please? Is it possible that the files I used from here (http://notepad-plus-plus.org/contribute/plugin-howto.html) might be too old with my NP++ version (6.2.3) or is it another problem?

     
  • jmiller1
    jmiller1
    2013-03-30

    Please, can someone help me please?
    I almost finished my plugin but I can't get it to work in NPP because the exception (see above) popups up every time. I tried to compile the NPP source myself to test and see where the exceptions comes from, but for some reason it doesn't appear in my self-compiled NPP executable (it works there). This is very confusing. But I can't publish my plugin because it raises the exception from above with the native NPP executable. Please help me.

    Here is a blank test project (source & DLL):
    DLL: http://www.file-upload.net/download-7401689/ccc.zip.html
    Source: http://www.file-upload.net/download-7401691/ccc_source.zip.html

     
    Last edit: jmiller1 2013-03-30
  • Don R
    Don R
    2013-04-03

    I have RAD Studio XE and XE3. I use Delphi but not C++ Builder. Your IDE configuration is likely correct. While experimenting with my Color Picker plugin I sometimes broke the plugin with Windows Message calls. Your plugin is doing something similar with WM_CREATE. Obviously, the plugin must be created somehow. With a plugin coded in Delphi, the creation is called in the Initialization section. I don't know how initialization is done in Builder. There are some ideas on stack overflow and on the Embarcadero wiki and forums. I hope this helps somehow.

     
  • jmiller1
    jmiller1
    2013-04-04

    The weird thing is: It works perfectly if Notepad++ is compiled and run in debug mode (but then NPP throws assert errors if non-ascii characters are typed in..). Only when NPP is compiled in release mode this happens. Also this exception is thrown by NPP, not my plugin. For some reason NPP's function PluginsManager::loadPlugin() loads my plugin without any problem, but exactly after it returns ("return (_pluginInfos.size() - 1);"), it throws this exception. The return value is correct and not the reason. That's weird. I found out that this happens only when NPP calls the setInfo() function in my plugin to send his 3 handlers in a struct. My plugin just stores them exactly as shown in the templates from NPP (and I mean it works in debug mode). I even tried to comment out everything in my setInfo() function so it is completely empty and does absolutely nothing. But still somehow... I don't know what I can do more. If at least someone had a simple working C++Builder template. I think I have no other option other than to port my code to Delphi. But thank you for your help, Don! I appreciate it.

     
    Last edit: jmiller1 2013-04-04
  • Don R
    Don R
    2013-04-07

    Take a look at the char pointers. In Delphi, pchar and pansichar are the same in ANSI versions of Delphi but in the Unicode IDEs these pointers are not the same. In my color picker plugin I wanted to have ascii output so I removed the pointers in a parameter that outputs the string with this: LPARAM(AnsiString(ColorStr)).