Click here to Skip to main content
15,888,208 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Top level menu - Message on losing focus Pin
Code-o-mat9-Jan-12 6:14
Code-o-mat9-Jan-12 6:14 
QuestionLog event message Pin
_Flaviu8-Jan-12 22:58
_Flaviu8-Jan-12 22:58 
AnswerRe: Log event message Pin
Chandrasekharan P8-Jan-12 23:38
Chandrasekharan P8-Jan-12 23:38 
QuestionWinSNMP Pin
msr_codeproject8-Jan-12 19:40
msr_codeproject8-Jan-12 19:40 
AnswerRe: WinSNMP Pin
Richard MacCutchan8-Jan-12 22:55
mveRichard MacCutchan8-Jan-12 22:55 
AnswerRe: WinSNMP Pin
S p k 5219-Jan-12 19:16
S p k 5219-Jan-12 19:16 
QuestionCalling via TAPI Pin
Hadi Dayvary7-Jan-12 4:03
professionalHadi Dayvary7-Jan-12 4:03 
Question#pragma data_seg issue - Sharing only works with multiple instances of the same EXE Pin
bcb_guy6-Jan-12 21:00
bcb_guy6-Jan-12 21:00 
Hi again,

I am using data_segs to share an LPSTR variable but the sharing only seems to work with multiple instances of the same EXE - literally. When I retrieve the value of the var from another app, a different EXE, I get the default value of the variable originally initialized in the module.

Code in DLL:

C++
#pragma data_seg("Shared")
__declspec(dllexport) LPSTR lpsCommandParameter = NULL;
#pragma data_seg()
#pragma comment(linker,"/SECTION:Shared,S")

extern "C"
{
	__declspec(dllexport) VOID SetCommandParameter(LPSTR lpsParam);
	__declspec(dllexport) LPSTR GetCommandParameter();
}


VOID SetCommandParameter(LPSTR lpsParam)
{
	lpsCommandParameter = lpsParam;
}

LPSTR GetCommandParameter()
{
	return lpsCommandParameter;
}


Code in Form1.cpp (Form1.exe) - Button1_Click - This button sets the value of lpsCommandParameter to "Hello"
C++
typedef VOID (*pSetCommandParameter)(char *lpsParam);
HINSTANCE DllHandle = LoadLibraryW(L"my.dll");

if (DllHandle == NULL)
{
    ShowMessage("NULL");
    return;
}

pSetCommandParameter pSetParam = (pSetCommandParameter)GetProcAddress(DllHandle, "SetCommandParameter");

if (pSetParam == NULL)
{
    ShowMessage("pSetParam is NULL");
    return;
}

pSetParam("Hello");



Code in Form1.cpp (Form1.exe) - Button2_Click - This one retrieves the value of lpsCommandParameter:

C++
typedef char *( *pGetCommandParameter )();
HINSTANCE DllHandle = LoadLibraryW(L"my.dll");

if (DllHandle == NULL)
{
    ShowMessage("NULL");
    return;
}

pGetCommandParameter pGetParam = (pGetCommandParameter)GetProcAddress(DllHandle, "GetCommandParameter");

if (pGetParam == NULL)
{
    ShowMessage("pGetParam is NULL");
    return;
}

ShowMessage(pGetParam());


Now the sharing works fine as long as multiple instances of that same Form1.exe are instantiated. Put the Button2 code in a second application, say Form2.exe and click the button to retrieve the value of lpsCommandParameter and you'll get a blank. I instantiated 4 instances of Form1.exe and the value of lpsCommandParameter from the DLL is returned fine but I keep getting blanks from a different EXE. I want this data to be visible among different EXEs as my project depends on shared data and I don't want to write anything on disk so I really want do this via data sharing in DLLs.
AnswerRe: #pragma data_seg issue - Sharing only works with multiple instances of the same EXE Pin
bcb_guy7-Jan-12 10:37
bcb_guy7-Jan-12 10:37 
QuestionDLL global variable question - VC++ 2010 Express - unable to set Pin
bcb_guy6-Jan-12 15:17
bcb_guy6-Jan-12 15:17 
AnswerRe: DLL global variable question - VC++ 2010 Express - unable to set Pin
«_Superman_»6-Jan-12 15:56
professional«_Superman_»6-Jan-12 15:56 
GeneralRe: DLL global variable question - VC++ 2010 Express - unable to set Pin
bcb_guy6-Jan-12 16:53
bcb_guy6-Jan-12 16:53 
Questionpackage and deployment for VC6 Pin
azhari246-Jan-12 2:41
azhari246-Jan-12 2:41 
AnswerRe: package and deployment for VC6 Pin
Maximilien6-Jan-12 9:23
Maximilien6-Jan-12 9:23 
GeneralRe: package and deployment for VC6 Pin
azhari246-Jan-12 17:27
azhari246-Jan-12 17:27 
AnswerRe: package and deployment for VC6 Pin
jeron16-Jan-12 11:01
jeron16-Jan-12 11:01 
GeneralRe: package and deployment for VC6 Pin
azhari246-Jan-12 17:32
azhari246-Jan-12 17:32 
AnswerRe: package and deployment for VC6 Pin
Andy41113-Jan-12 3:56
Andy41113-Jan-12 3:56 
QuestionWhich IDE you use for development on Linux platforms? Pin
rahul.kulshreshtha5-Jan-12 23:51
rahul.kulshreshtha5-Jan-12 23:51 
AnswerRe: Which IDE you use for development on Linux platforms? Pin
Richard MacCutchan6-Jan-12 0:52
mveRichard MacCutchan6-Jan-12 0:52 
GeneralRe: Which IDE you use for development on Linux platforms? Pin
rahul.kulshreshtha6-Jan-12 1:54
rahul.kulshreshtha6-Jan-12 1:54 
AnswerRe: Which IDE you use for development on Linux platforms? Pin
Nemanja Trifunovic7-Jan-12 12:55
Nemanja Trifunovic7-Jan-12 12:55 
GeneralRe: Which IDE you use for development on Linux platforms? Pin
richard_k9-Jan-12 7:50
richard_k9-Jan-12 7:50 
AnswerRe: Which IDE you use for development on Linux platforms? Pin
richard_k9-Jan-12 7:55
richard_k9-Jan-12 7:55 
JokeRe: Which IDE you use for development on Linux platforms? Pin
Wes Aday10-Jan-12 11:40
professionalWes Aday10-Jan-12 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.