⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydll.c

📁 LabWindows/CVI调用DLL实用例程(菜农HotPower)
💻 C
字号:
/* A simple example of using a uir in a dll created both in cvi or an
 * external compiler.
 */

/* Include files needed to compile DLL */
#include <windows.h>
#include <cvirte.h>     /* needed if linking DLL in external compiler; harmless otherwise */
#include <userint.h>
#include "dlluir.h"

static long int status = 0;
static int lightVal = 0, panelHandle;

BOOL __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
     /* The DllMain function is called when ever the DLL is loaded and    */
     /* unloaded. Place Initialization code for the DLL in this function. */
    if (fdwReason == DLL_PROCESS_ATTACH) {
        /* Place any initialization which needs to be done when the DLL */
        /* is loaded here. */
        if (InitCVIRTE (hinstDLL, 0, 0) == 0)       /* needed if linking DLL in external compiler; harmless otherwise */
            return 0;   /* out of memory */
        status = 100;
    } else if (fdwReason == DLL_PROCESS_DETACH) {
        /* Place any clean-up which needs to be done when the DLL */
        /* is unloaded here. */
        CloseCVIRTE ();     /* needed if linking DLL in external compiler; harmless otherwise */
    }
    /* return FALSE to abort if initialization fails */
    return TRUE;
}

BOOL __stdcall DllEntryPoint (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    return DllMain(hinstDLL, fdwReason, lpvReserved);
}

void DLLEXPORT RunDllUI (void)
{
    /* Call this function from the appropriate place in your code */
    /* to load and display startup panels.                        */

    panelHandle = LoadPanelEx (0, "dlluir.uir", PANEL, __CVIUserHInst);
    DisplayPanel (panelHandle);
    RunUserInterface ();
}

int CVICALLBACK CloseUICallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event) {
        case EVENT_COMMIT:
            HidePanel(panelHandle);
            DiscardPanel(panelHandle);
            QuitUserInterface(0);
            break;
    }
    return 0;
}

int CVICALLBACK LightSwitchCallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event) {
        case EVENT_COMMIT:
            GetCtrlVal (panelHandle, PANEL_BINARYSWITCH, &lightVal);
            SetCtrlVal (panelHandle, PANEL_LED, lightVal);
            break;
    }
    return 0;
}

long int DLLEXPORT __stdcall MyDLLStdcallFunction(LPSTR buffer)
{
     MessageBox(NULL, buffer, "DLL MessageBox called from MyDLLStdcallFunction", MB_OK);
     status = 200;
     return  (status);
}


long int DLLEXPORT MyDLLCdeclFunction(LPSTR buffer)
{
     MessageBox(NULL, buffer, "DLL MessageBox called from MyDLLCdeclFunction", MB_OK);
     status = 300;
     return  (status);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -