CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

trouble using unmanaged c++ from c# using dllimport topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-07-2010, 07:13 AM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
alag20 is on a distinguished road
| More
trouble using unmanaged c++ from c# using dllimport

Hi guys,
i am having trouble importing c++ unmanaged dll into C# [winform]. Can someone help?

Basically i am just trying to create a safearray of strings in c++ and trying to send it to C#.


Here is my c++ code.

Code:
extern "C" __declspec(dllexport) BOOL GetStringArr(SAFEARRAY* arr)
{
SAFEARRAY*    myArray;
  SAFEARRAYBOUND  rgsabound[1];

  rgsabound[0].lLbound = 0;
  rgsabound[0].cElements = 5;

  myArray = SafeArrayCreate(VT_BSTR, 1, rgsabound);
  VARIANT* pvData = (VARIANT*)(myArray->pvData);

  pvData[0].vt = VT_BSTR;
  pvData[0].bstrVal = SysAllocString(L"FirstString");
  pvData[1].vt = VT_BSTR;
  pvData[1].bstrVal = SysAllocString(L"SecondString");
  pvData[2].vt = VT_BSTR;
  pvData[2].bstrVal = SysAllocString(L"ThirdString");
  pvData[3].vt = VT_BSTR;
  pvData[3].bstrVal = SysAllocString(L"FourthString");
  pvData[4].vt = VT_BSTR;
  pvData[4].bstrVal = SysAllocString(L"FifthString");

  arr = myArray;
  return true;
}
Here is my c# code.

[DllImport("MyData.dll", EntryPoint = "GetStringArr")]
public static extern bool GetStringArr([MarshalAs(UnmanagedType.SafeArray)] out Array strServerList);



i am getting exception when i call GetStringArr from C#. i am sure there is something silly i am doing. Can someone please help?



Thanks in advance.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C Sharp help on pointers unmanaged code augusbas C# Programming 0 09-05-2010 09:15 AM
Decimal to binary conversion trouble bmos31 C++ Programming 1 08-31-2010 10:16 PM
I have trouble installing external libraries jamort C++ Programming 0 08-31-2010 04:11 AM
Trouble navigating NyARToolkit Suit C# Programming 0 08-31-2010 04:11 AM
trouble with CFormView print preview?an answer. praxisist MFC Programming 0 06-13-2008 01:34 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:48 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board