I am creating a Win32 Dll Wrapper around my C# class library.

I am able to pass string from my C# to C++ application.
But i am not sure as to how can i pass string array in Win32 C++ project.

//C# code
void Test(string lFile, int ver);
//C++ Code
extern "C" __declspec(dllexport)
void _stdcall Test(char *lFile, int ver)
{
	//Initialize COM.
	psShrinkGrowD->Shrink(_bstr_t(largeFile), version);
	// Uninitialize COM.
}

I am able to pass string which is (char array in C++) and able to receive string.

But if i want to pass string array suppose
void Test(string[] versions) then is there any way to do it in Win32 C++ Project.

Help would be really appreciated.

Recommended Answers

All 3 Replies

what you apparently want is an array of _bstr_t objects. The COM way of doing that is to create a SAFEARRAY. Here is an article about them. I don't know how to use them from C#, but since your code used _bstr_t class then I would assume that it can use SAFEARRAY.

SAFEARRAY is not working fine with me.
It throws memory corrupt error.

Post code because I can't see your computer's monitor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.