<p>I've got a Windows DLL that I wrote, written in C/C++ (all exported functions are 'C'). The DLL works fine for me in VC++. I've given the DLL to another company who do all their development in VB. They seem to be having a problem linking to the functions. I haven't used VB in ten years and I don't even have it installed. What could be the problem?</p>

<p>I've declared all my public functions as follows:</p>

<pre><code>#define MYDCC_API __declspec(dllexport)


MYDCCL_API unsigned long MYDCC_GetVer( void);
.
.
.
</code></pre>

<p>Any ideas?</p>

<hr>

<p>Finally got back to this today and have it working. The answers put me on the right track but I found this most helpful:</p>

<p><a href="http://www.codeproject.com/KB/DLL/XDllPt2.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/DLL/XDllPt2.aspx</a></p>

<p>Also, I had a few problems passing strings to the DLL functions, I found this helpful:</p>

<p><a href="http://www.flipcode.com/archives/Interfacing_Visual_Basic_And_C.shtml" rel="nofollow noreferrer">http://www.flipcode.com/archives/Interfacing_Visual_Basic_And_C.shtml</a></p>

<hr>

[{'answer_id': 39478, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 3, 'selected': True, 'text': '<p>By using <code>__declspec</code> for export, the function name will get exported <em>mangled</em>, i.e. contain type information to help the C++ compiler resolve overloads.</p>\n\n<p>VB6 cannot handle mangled names. As a workaround, you have to de-mangle the names. The easiest solution is to link the DLL file using an <a href="http://msdn.microsoft.com/en-us/library/d91k01sh%28VS.80%29.aspx" rel="nofollow noreferrer">export definition</a> file in VC++. The export definition file is very simple and just contains the name of the DLL and a list of exported functions:</p>\n\n<pre><code>LIBRARY mylibname\nEXPORTS\n    myfirstfunction\n    secondfunction\n</code></pre>\n\n<p>Additionally, you have to specify the <code>stdcall</code> calling convention because that\'s the only calling convention VB6 can handle. There\'s a project using assembly injection to handle C calls but I guess you don\'t want to use this difficult and error-prone method.</p>\n'}, {'answer_id': 39479, 'author': 'Re0sless', 'author_id': 2098, 'author_profile': 'https://Stackoverflow.com/users/2098', 'pm_score': 2, 'selected': False, 'text': '<p>Try adding __stdcall at the end</p>\n\n<pre><code>#define MYDCC_API __declspec(dllexport) __stdcall\n</code></pre>\n\n<p>We have some C++ dlls that interact with our old VB6 apps and they all have that at the end.</p>\n'}, {'answer_id': 2742624, 'author': 'tracker', 'author_id': 329506, 'author_profile': 'https://Stackoverflow.com/users/329506', 'pm_score': 0, 'selected': False, 'text': '<p>A VB6 DLL is always a COM dll. I shall describe an example in as few words as possible. Suppose you have a ActiveX DLL project in VB6 with a class called CTest which contains a method as shown below</p>\n\n<p>Public Function vbConcat(ByVal a As String, ByVal b As String) As String\n    vbConcat = a &amp; b\nEnd Function</p>\n\n<p>and you have set the project name as VBTestLib in VB6 project properties and\nyou have compiled the project as F:\\proj\\VB6\\ActiveXDLL\\VBTestDLL.dll</p>\n\n<p>You need to register the dll using the Windows command \nregsvr32  F:\\proj\\VB6\\ActiveXDLL\\VBTestDLL.dll</p>\n\n<p>now your C++ code :</p>\n\n<p>#import "F:\\proj\\VB6\\ActiveXDLL\\VBTestDLL.dll"\n using namespace VBTestLib;</p>\n\n<p>void CDialogTestDlg::OnButton1() \n   {</p>\n\n<pre><code> HRESULT hresult;\n CLSID clsid;\n _CTest *t; // a pointer to the CTest object\n _bstr_t bstrA = L"hello";\n _bstr_t bstrB = L" world"; \n _bstr_t bstrR;\n ::CoInitialize(NULL);\n  hresult=CLSIDFromProgID(OLESTR("VBTestLib.CTest"), &amp;clsid);\n  hresult= CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,\n                               __uuidof(_CTest),(LPVOID*) &amp;t);\n  if(hresult == S_OK)\n  {\n     bstrR  = t-&gt;vbConcat(bstrA , bstrB);\n     AfxMessageBox((char*)bstrR);\n   }\n</code></pre>\n\n<p>}</p>\n\n<p>That\'s all there is to it,  to get started off.    </p>\n'}]
['https://Stackoverflow.com/questions/39468', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3685/']