title: EditStreamCallback with C#, Migrating from C++
body: <p>I am trying to accomplish much the same thing as is being done here <a href="http://www.vbforums.com/showthread.php?t=449171" rel="nofollow noreferrer">http://www.vbforums.com/showthread.php?t=449171</a></p>
  
  <p>However using C#, instead of VB. What is snagging me the most is the C++ portion of the code. I have little to no experience with C++, and I have tried time and time again to make this '.dll' being spoken of, but it won't compile right without changing things (I have to change the GetModuleHandle section to have Text("") in it, and such)</p>
  
  <p>Then when I mount it up in C#, I get an error that 'No suitable entry point could be found for GetAddr(), even though I follow the same P/Invoke signature as explained (in C# syntax instead of VB). </p>
  
  <p>Can anyone help me? I cannot get this C++ .dll made correctly. I don't even know the appropriate way to make the right kind of project to do this. The C++ code in question is listed below, and I am using Visual Studio 2010.</p>
  
  <pre><code>#include "stdafx.h"
  
  #pragma data_seg(".shared")
  char sharedStr[255] = "a";
  char sharedRichTextBoxString[255] = "a";
  int addr = 0;
  HMODULE module = 0;
  int flag = 0;
  #pragma data_seg()
  #pragma comment(linker, "/SECTION:.shared,RWS")    
  
  BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
  {
      if(flag == 0) 
      {
          module = GetModuleHandle("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\EditStreamCallBack\\Debug\\EditStreamCallBack.dll");
          addr = (int)GetProcAddress(module, (LPCSTR)"EditStreamCallBack");
          flag = 1;
      }
      return TRUE;
  }
  
  __declspec(dllexport) void _stdcall SetText(char * str)
  {
      int sz = strlen(str);
      memcpy(sharedStr, str, sz);     
  }
  
  __declspec(dllexport) HMODULE _stdcall GetModuleH()
  {
      return module;
  }
  
  __declspec(dllexport) int _stdcall GetAddr() 
  {
      return addr;
  }    
  
  __declspec(dllexport) char * _stdcall GetRichTextBoxString()
  {
      return sharedRichTextBoxString;
  }    
  
  __declspec(dllexport) int CALLBACK EditStreamCallBack(DWORD dwCookie, LPBYTE buf, DWORD numByte, DWORD* cb)
  {
      if(dwCookie==1) //if 1, then we want it to work for EM_STREAMIN
      {
          memcpy(buf, sharedStr, strlen(sharedStr));
          *cb = strlen(sharedStr);
      }
      else if(dwCookie==2) //if 2, then we want it to work for EM_STREAMOUT
      {
          memcpy(sharedRichTextBoxString, buf, numByte);
      }
      return 0;
  }
  </code></pre>