欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Sharing a single dll among multiple processes.

Sharing a single dll among multiple processes.

  • Wednesday, November 22, 2006 5:21 PM
    Mansoor Ali
     

     

    Hello,

    I have a DLL, created using VC7 and that DLL is to be used by two EXEs, I need to know, whether it is possible load the DLL only once, so that the same instance is used by both the EXEs. If its possible then how it is done.

    Thanx.

     

     

Answers

  • Wednesday, November 22, 2006 6:39 PM
     

I hope you need data that will be shared cross two processes.

See, this thread.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=921874&SiteID=1

You can declare process shared section

#pragma section(".shared", read, write, shared)

 

Then use __declspec(allocate(".shared")) to declare shared data.

#define SHARED __declspec(allocate(".shared"))

SHARED volatile LONG g_nInstances = 0; //Cross process shared varible of long tipe

SHARED volatile MSG msg = {0}; //Cross process shared structure (MSG type)

You also, can use WM_COPYDATA message for cross process interaction.

Compile this Win32 console application. Run many instances of this application. See, the output. First you see a shared section.

// ProcessMarshal.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <windows.h>

#include <iostream>

#include <time.h>

using namespace std;

#pragma section(".shared", read, write, shared)

#define SHARED __declspec(allocate(".shared"))

SHARED volatile //volatile required because a compiler can generate a code, that will store and change data in register.

//thats why you can unpredictable results.

LONG g_nInstances = 0;

SHARED volatile MSG msg = {0};

void CopyData();

int _tmain(int argc, _TCHAR* argv[])

{

InterlockedIncrement(&g_nInstances);// Synchronization because another process can access for

// this field. Interlocked is enough.

cout<<g_nInstances<<endl;

HANDLE hMutex = ::CreateMutex(NULL, FALSE, _T("SyncShared")); //Name required to access the same mutex from different processes.

if(WAIT_FAILED != ::WaitForSingleObject(hMutex, INFINITE))

// Synchronization by mutex because you need update entire structure.

// You cannot use interlocked here, because some field can update one process, some a second.

{

msg.message++;

msg.time += 10;

cout<<"msg.message = "<<msg.message<<endl;

cout<<"msg.time = "<<msg.time<<endl;

ReleaseMutex(hMutex);

}

// Sends a structure vs WM_COPYDATA.

CopyData();

cin.get();

return 0;

}

bool isAny = false;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)

{

TCHAR name[256];

GetWindowText(hwnd, name, 255);

if(_tcscmp(name, _T("Form1")) == 0)

{

MSG msg = {NULL};

msg.message = g_nInstances;

msg.time = 31;

COPYDATASTRUCT cd = {0};

cd.cbData = sizeof(msg);

cd.dwData = 1;

cd.lpData = &msg;

cout<<"Send Copy Data"<<endl;

SendMessage(hwnd, WM_COPYDATA, NULL, (LPARAM)&cd);

isAny = true;

}

return 1;

}

void CopyData()

{

EnumWindows(&EnumWindowsProc, NULL);

if(!isAny)

cout<<"No windows"<<endl;

}

All Replies

  • Wednesday, November 22, 2006 6:39 PM
    Aleksandr Tokarev
     

    I hope you need data that will be shared cross two processes.

    See, this thread.

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=921874&SiteID=1

    You can declare process shared section

    #pragma section(".shared", read, write, shared)

     

    Then use __declspec(allocate(".shared")) to declare shared data.

    #define SHARED __declspec(allocate(".shared"))

    SHARED volatile LONG g_nInstances = 0; //Cross process shared varible of long tipe

    SHARED volatile MSG msg = {0}; //Cross process shared structure (MSG type)

    You also, can use WM_COPYDATA message for cross process interaction.

    Compile this Win32 console application. Run many instances of this application. See, the output. First you see a shared section.

    // ProcessMarshal.cpp : Defines the entry point for the console application.

    //

    #include "stdafx.h"

    #include <windows.h>

    #include <iostream>

    #include <time.h>

    using namespace std;

    #pragma section(".shared", read, write, shared)

    #define SHARED __declspec(allocate(".shared"))

    SHARED volatile //volatile required because a compiler can generate a code, that will store and change data in register.

    //thats why you can unpredictable results.

    LONG g_nInstances = 0;

    SHARED volatile MSG msg = {0};

    void CopyData();

    int _tmain(int argc, _TCHAR* argv[])

    {

    InterlockedIncrement(&g_nInstances);// Synchronization because another process can access for

    // this field. Interlocked is enough.

    cout<<g_nInstances<<endl;

    HANDLE hMutex = ::CreateMutex(NULL, FALSE, _T("SyncShared")); //Name required to access the same mutex from different processes.

    if(WAIT_FAILED != ::WaitForSingleObject(hMutex, INFINITE))

    // Synchronization by mutex because you need update entire structure.

    // You cannot use interlocked here, because some field can update one process, some a second.

    {

    msg.message++;

    msg.time += 10;

    cout<<"msg.message = "<<msg.message<<endl;

    cout<<"msg.time = "<<msg.time<<endl;

    ReleaseMutex(hMutex);

    }

    // Sends a structure vs WM_COPYDATA.

    CopyData();

    cin.get();

    return 0;

    }

    bool isAny = false;

    BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)

    {

    TCHAR name[256];

    GetWindowText(hwnd, name, 255);

    if(_tcscmp(name, _T("Form1")) == 0)

    {

    MSG msg = {NULL};

    msg.message = g_nInstances;

    msg.time = 31;

    COPYDATASTRUCT cd = {0};

    cd.cbData = sizeof(msg);

    cd.dwData = 1;

    cd.lpData = &msg;

    cout<<"Send Copy Data"<<endl;

    SendMessage(hwnd, WM_COPYDATA, NULL, (LPARAM)&cd);

    isAny = true;

    }

    return 1;

    }

    void CopyData()

    {

    EnumWindows(&EnumWindowsProc, NULL);

    if(!isAny)

    cout<<"No windows"<<endl;

    }

  • Wednesday, November 22, 2006 6:44 PM
    Aleksandr Tokarev
     

    To load one instance of a dll in two process imposible. Each process loads its own dll-instance. But, share data cross process posible. See, above post.

    Memory pages with code somtimes shared, across process, but I think it nevermind for you.

  • Thursday, November 23, 2006 9:03 AM
    Mansoor Ali
     
    I have a Dll that makes a socket connection with the server, and there are two client applications both use that Dll, I want only single connection to the server using that DLL.

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
VC++ DLL調式方法?。ㄞD)
智能指針shared
178 f0602
Phpredis 
Win32控制臺程序的定時(shí)器實(shí)現
【轉】C++ 智能指針詳解
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久