Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/07/2011, 22:38
nostromos
 
Fecha de Ingreso: agosto-2009
Mensajes: 23
Antigüedad: 14 años, 8 meses
Puntos: 2
Pregunta crear ventana desde DLL C++

Holas;

Estoy desarrollando una libreria en dll, la cual creo una ventana que se llama desde visual basic, podría colocar un form, bueno hay que hacer cosas novedosas.

El codigo a continuación lo he estado compilando en DevC++ y CodeBlocks, los errores son:

Errores en Dev-C++:

Código PHP:
[Linker Errorundefined reference to `GetStockObject@4' 
Código PHP:
[Linker Errorundefined reference to `TextOutA@20' 
Errores en CodeBlocks:

Código PHP:
||=== cppWIN_DIALOGDebug ===|
main.cpp||In function 'LRESULT WindProc(HWND__*, UINT, WPARAM, LPARAM)':|
main.cpp|93|warningdeprecated conversion from string constant to 'char*'|
objDebugmain.o||In function `MAKE_cppWIN_MAIN@16':|
main.cpp|50|undefined reference to 
`GetStockObject@4'|
obj\Debug\main.o||In function `Z8WindProcP6HWND__jjl@16'
:|
main.cpp|104|undefined reference to `TextOutA@20'|
||=== Build finished: 2 errors, 1 warnings ===| 
Código dllmain.cpp:

Código PHP:
#include "dll.h"
#include <windows.h>
#include <cstring>
#include <cstdio>
#include <cstdlib>

BOOL APIENTRY DllMain (HINSTANCE hInstDWORD reasonLPVOID reserved)
{
    switch (
reason)
    {
      case 
DLL_PROCESS_ATTACH:
        break;

      case 
DLL_PROCESS_DETACH:
        break;

      case 
DLL_THREAD_ATTACH:
        break;

      case 
DLL_THREAD_DETACH:
        break;
    }

    
/* Returns TRUE on success, FALSE on failure */
    
return TRUE;
}
//--- DECLARACION DE PROTOTIPOS
LRESULT CALLBACK WindProc(HWND,UINT,WPARAM,LPARAM);
//-------------------------------------------------------------
extern "C"
{
    
DLL_EXPORTAR _stdcall int MAKE_cppWIN_MAIN(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR pszCmdLine,int nCmdShow)
    {
        
HWND hWnd;
        
MSG msg;
        
WNDCLASS wndClass;
        static 
char szAppName[] ="Prog WIN32";
        
wndClass.style        =0;
        
wndClass.lpfnWndProc=WindProc;
        
wndClass.cbClsExtra =0;
        
wndClass.cbWndExtra =0;
        
wndClass.hInstance  =hInst;
        
wndClass.hIcon        =LoadIcon(NULL,IDI_APPLICATION);
        
wndClass.hCursor    =LoadCursor(NULL,IDC_ARROW);
        
//wndClass.hbrBackground=HBRUSH(COLOR_APPWORKSPACE+1);
        
wndClass.hbrBackground=(HBRUSHGetStockObject(WHITE_BRUSH);
        
wndClass.lpszMenuName=NULL;
        
wndClass.lpszClassName=szAppName;

        if (
RegisterClass(&wndClass)==0)
          return 
0;

        
hWnd=CreateWindow
        
(szAppName,//nom de la classe
        
szAppName//titre
        
WS_OVERLAPPEDWINDOW//type de fenêtre
        
CW_USEDEFAULT//X
        
CW_USEDEFAULT// et y initial
        
500//taille x
        
500// et    y
        
NULL,//handle de la fenêtre-mère
        
NULL,//handle du menu
        
hInst,//handle de l'instance du programme
        
NULL); //param de création

    
if (hWnd==0)
    {
        
UnregisterClass(szAppName,hInst);
        return 
0;
    }


    
ShowWindow(hWnd,SW_SHOWDEFAULT);
    
UpdateWindow (hWnd);

    while(
GetMessage(&msg,NULL,0,0))
    {
        
TranslateMessage(&msg);
        
DispatchMessage(&msg);
    }
    
UnregisterClass(szAppName,hInst);
    return 
msg.wParam;

    }
}
//---PROCEDIMIENTO DE VENTANA
LRESULT CALLBACK WindProc(HWND hWnd,UINT proc,WPARAM wParam,LPARAM lParam)
{
    static 
char *pszHello="Hello";

    switch(
proc)
    {
        case 
WM_CREATE:
            return 
TRUE;
            break;
        case 
WM_PAINT:
            
HDC hDC;
            
PAINTSTRUCT paintStruct;
            
hDC=BeginPaint(hWnd,&paintStruct);
            
TextOut(hDC,0,0,pszHello,lstrlen(pszHello));
            
EndPaint(hWnd,&paintStruct);
            return 
0;
            break;
        case 
WM_DESTROY:
            
PostQuitMessage(0);
            return 
0;
            break;
        default:
            return 
DefWindowProc(hWnd,proc,wParam,lParam);
    }

Código dll.h:

Código PHP:
# define DLL_EXPORTAR __declspec (dllexport) 
Cuando creo un proyecto en Win32 todo bien.

La otra duda es, cuando compilo una ventana normal en Win32 en codeblocks, me aparece una ventana negra detrás del programa recién creado, es normal, en compiladores antiguos esto no me pasaba.

Me pueden ayudar en que estoy mal.

Nos vemos....