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

📄 sampdll.cpp

📁 window下的多线程编程参考书。值得一读
💻 CPP
字号:
//
// FILE: sampdll.cpp
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////

#include <windows.h>

#define EXPORT_SAMPDLL_API
#include "sampdll.h"

class CFoo
{
    public:
        CFoo( int iInstance )
            : m_iInstance(iInstance)
        {
            wsprintf(m_szMsgBuf, "CFoo::CFoo(%d)\n", m_iInstance);
            OutputDebugString(m_szMsgBuf);
        }

        ~CFoo()
        {
            wsprintf(m_szMsgBuf, "CFoo::~CFoo(%d)\n", m_iInstance);
            OutputDebugString(m_szMsgBuf);
        }
    
    private:
        int     m_iInstance;
        char    m_szMsgBuf[80];
};

CFoo    Foo(1);
CFoo    AnotherFoo(2);

BOOL WINAPI DllMain
(
    HANDLE  hInst, 
    ULONG   dwReason,
    LPVOID  lpReserved
)
{
    switch( dwReason )
    {
        case DLL_PROCESS_ATTACH:
            OutputDebugString("DLL_PROCESS_ATTACH\n");

            if( lpReserved )
            {   
                OutputDebugString("lpReserved != NULL\n");
            }
            else
            {
                OutputDebugString("lpReserved == NULL\n");
            }
        break;

        case DLL_THREAD_ATTACH:
            OutputDebugString("DLL_THREAD_ATTACH\n");
        break;

        case DLL_THREAD_DETACH:
            OutputDebugString("DLL_THREAD_DETACH\n");
        break;

        case DLL_PROCESS_DETACH:
            OutputDebugString("DLL_PROCESS_DETACH\n");
        break;
    }

    // Return FALSE to cause the load for sampdll.dll to fail.
    //
    return(TRUE);
}

SAMPDLL_API void __stdcall SayHello( void )
{
    OutputDebugString("Hello from sampdll.dll!\n");
}

⌨️ 快捷键说明

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