Well, I'm trying this just to make sure I can compile a decent .dll under Code::Blocks and MinGW (i'm using Npp v3.9), but I always seem to get the "FuncItems array not set correctly" error at startup.
It seems there are some problems with exporting functions when compiling with MiniGW. But the NPPTextFX plugin (by Chris Severance) is compiled with Dev-C++, as I understand. So the only way I see is to ask Chris Severance how did he compile his dll.
By the way, I tried to compile the sources of NPPTextFX (NPPTextFX23-v0.23ReleaseSource) in Dev-C++ - but the compiler says there are a lot of undefined functions there. I had not much time to investigate what files must be included to compile this project.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to follow up in case anyone hasn't found it already, Chris Severance has an exhaustive look into the subject of win32 dlls and various compilers here: http://forums.codeblocks.org/index.php/topic,946.0.html
For mingw (Dev-C++, code::blocks), the insertPlugin demo compiles and loads correctly once DllMain is declared as extern "C"
Maybe definition of "bool" type is different? If I'm not wrong, "bool" is "byte" in last versions of VC++, but maybe it is "word" or "int" in Code::Blocks?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry,
I should have been more specific. In VS, when you compile a program in debug mode it adds debugging symbols and that can add a significant bulk to the size of the executable. I know in VS 6 this was the default configuration and I think it carried over into .net but I don't develop in C++ on VS anymore. :-D
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hate to say this, but I'm installing MS's Visual Studio .NET. :/
I wish there was a way to use MinGW's dll's... If someone would like to help out, I found these usefull sites, but I couldn't make anything good out of them.
Well, I'm trying this just to make sure I can compile a decent .dll under Code::Blocks and MinGW (i'm using Npp v3.9), but I always seem to get the "FuncItems array not set correctly" error at startup.
What's wrong?
Here's the code:
#include "PluginInterface.h"
const char PLUGIN_NAME[] = "Test";
NppData nppData;
const int nbFunc = 1;
FuncItem funcItem[nbFunc];
// funcoes
void insertDateTime();
// main
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD reasonForCall,
LPVOID lpReserved )
{
switch (reasonForCall)
{
case DLL_PROCESS_ATTACH:
{
funcItem[0]._pFunc = insertDateTime;
strcpy(funcItem[0]._itemName, "Date & Time - short format");
funcItem[0]._init2Check = false;
funcItem[0]._pShKey = NULL;
}
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport) void setInfo(NppData notpadPlusData)
{
nppData = notpadPlusData;
}
extern "C" __declspec(dllexport) const char * getName()
{
return PLUGIN_NAME;
}
extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF)
{
*nbF = nbFunc;
return funcItem;
}
extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode)
{
}
extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
return TRUE;
}
HWND getCurrentHScintilla(int which)
{
return (which == 0)?nppData._scintillaMainHandle:nppData._scintillaSecondHandle;
};
void insertDateTime()
{
char date[128];
char time[128];
char dateTime[256];
SYSTEMTIME st;
GetLocalTime(&st);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, date, sizeof(date));
GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, time, sizeof(time));
wsprintf(dateTime, "%s %s", time, date);
int currentEdit;
SendMessage(nppData._nppHandle, WM_GETCURRENTSCINTILLA, 0, (LPARAM)¤tEdit);
SendMessage(getCurrentHScintilla(currentEdit), SCI_REPLACESEL, 0, (LPARAM)dateTime);
}
It seems there are some problems with exporting functions when compiling with MiniGW. But the NPPTextFX plugin (by Chris Severance) is compiled with Dev-C++, as I understand. So the only way I see is to ask Chris Severance how did he compile his dll.
By the way, I tried to compile the sources of NPPTextFX (NPPTextFX23-v0.23ReleaseSource) in Dev-C++ - but the compiler says there are a lot of undefined functions there. I had not much time to investigate what files must be included to compile this project.
Just to follow up in case anyone hasn't found it already, Chris Severance has an exhaustive look into the subject of win32 dlls and various compilers here: http://forums.codeblocks.org/index.php/topic,946.0.html
For mingw (Dev-C++, code::blocks), the insertPlugin demo compiles and loads correctly once DllMain is declared as extern "C"
extern "C" BOOL APIENTRY DllMain( HANDLE hModule, DWORD reasonForCall, LPVOID lpReserved )
and the linker option -lshlwapi is set.
Bahman
Maybe definition of "bool" type is different? If I'm not wrong, "bool" is "byte" in last versions of VC++, but maybe it is "word" or "int" in Code::Blocks?
:S Humm do you know how do I solve it?
I can compile, assemble and link. But Npp just won't take it.
Been checking Npp's source code, and I found this part:
for (int i = 0 ; i < pi->_nbFuncItem ; i++)
if (!pi->_funcItems[i]._pFunc)
throw string("\"FuncItems\" array is not set correctly");
... and it seems to me that my FuncItems array is well set. So why is Npp giving me this error?
Mmm... It seems correct your code to me.
Indeed, FuncItems array is well set.
Do you try to compile with VC++ compiler?
Don
Nop, I don't have it, but I'm pretty sure that's the problem.
MinGW's not compiling a decent dll. :/ damn
I managed to compile it at my University using Microsoft's VS.NET, and it worked.
Here's something interesting:
MinGW's DLL: 15,7 KB
.NET's DLL: 172 KB
Are you compiling in Debug or Release mode?
Well, I don't know. :/
Here's my Makefile, C::B generated it.
http://paste.uni.cc/11602
Sorry,
I should have been more specific. In VS, when you compile a program in debug mode it adds debugging symbols and that can add a significant bulk to the size of the executable. I know in VS 6 this was the default configuration and I think it carried over into .net but I don't develop in C++ on VS anymore. :-D
Hmm, but debugging symbols are meant for debugging, not for external references. :S DLL's compiled in Release mode should work too.
I'm not sure if that's the problem.
Hate to say this, but I'm installing MS's Visual Studio .NET. :/
I wish there was a way to use MinGW's dll's... If someone would like to help out, I found these usefull sites, but I couldn't make anything good out of them.
http://wyw.dcweb.cn/stdcall.htm
http://www.mingw.org/MinGWiki/index.php/MSVC-MinGW-DLL
http://www.outofhanwell.com/blog/index.php?title=linking_msvc_libraries_with_mingw_projec&more=1&c=1&tb=1&pb=1
http://www.geocities.com/yongweiwu/dllfaq.htm
Why don't you use Dev-Cpp? (http://www.bloodshed.net)
It uses MinGW's GCC.