Hi All thanks for the response ,
Actually I have to use non CLR C++ native code.
I got the answer from :
Here
see the Native Exe calling Managed Dll
Just twisted little bit for my need
C# code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CSDll
{
using System;
[
Guid("A2BDE14F-EC09-4E3C-9E39-A24B49352120")
]
public struct CSStObj
{
public int intData;
[MarshalAs(UnmanagedType.BStr)]
public string strData;
}
[Guid("D4660088-308E-49fb-AB1A-77224F3FF851")]
public interface IMyManagedInterface
{
int factorial(int arg);
void getCSObj(out CSStObj ob);
void getCSObjs([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_USERDEFINED)] out CSStObj[] ob);
}
[Guid("46A951AC-C2D9-48e0-97BE-91F3C9E7B065")]
public class Class1 : IMyManagedInterface
{
public Class1()
{
}
public int factorial(int arg)
{
int result;
if (arg == 1)
{
result = arg;
}
else
{
result = arg * factorial(arg - 1);
}
return result;
}
public void getCSObj(out CSStObj ob)
{
System.IO.TextWriter textWriter = System.Console.Out;
textWriter.WriteLine("getCSObj");
ob.intData = 7;
ob.strData = "hiCPP";
}
public void getCSObjs([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_USERDEFINED)] out CSStObj[] ob)
{
System.IO.TextWriter textWriter = System.Console.Out;
textWriter.WriteLine("getCSObjs");
ob =
new CSStObj[]{
new CSStObj() { intData = 1, strData = "1" },
new CSStObj() { intData = 2, strData = "2" },
new CSStObj() { intData = 3, strData = "3" }
};
}
}
}</csstobj>
In Atl non clr project
#include "stdafx.h"
#pragma once
#include "windows.h"
#include <stdio.h>
#import "C:\bin\CSDll.tlb" named_guids
int main(int argc, char* argv[])
{
try{
HRESULT hRes = S_OK;
CoInitialize(NULL);
CSDll::IMyManagedInterface *pManagedInterface = NULL;
hRes = CoCreateInstance(CSDll::CLSID_Class1, NULL, CLSCTX_INPROC_SERVER,
CSDll::IID_IMyManagedInterface, reinterpret_cast<void**> (&pManagedInterface));
if (S_OK == hRes)
{
long retVal =0;
hRes = pManagedInterface->raw_factorial(4, &retVal);
printf("The value returned by the dll is %ld\n",retVal);
CSDll::CSStObj stObj;
pManagedInterface->getCSObj(&stObj);
printf("getCSObj sent is %ld %s\n",stObj.intData,stObj.strData);
SAFEARRAY* saValues(NULL);
pManagedInterface->getCSObjs(&saValues);
CSDll::CSStObj* pVals;
HRESULT hr = SafeArrayAccessData(saValues, (void**)&pVals); if (SUCCEEDED(hr))
{
long lowerBound, upperBound; SafeArrayGetLBound(saValues, 1 , &lowerBound);
SafeArrayGetUBound(saValues, 1, &upperBound);
long cnt_elements = upperBound - lowerBound + 1;
for (int i = 0; i < cnt_elements; ++i) {
CSDll::CSStObj pVal = pVals[i];
printf("getCSObjs Array of Struct sent is %ld %s\n",pVal.intData,pVal.strData);
}
SafeArrayUnaccessData(saValues);
}
SafeArrayDestroy(saValues);
saValues = NULL;
pManagedInterface->Release();
}
} catch(_com_error& ce)
{
printf("Exception::%d||%s",ce.Error(),(wchar_t*)ce.Description());
}
CoUninitialize();
return 0;
}
and I got access to String,Structure,Array of Structure etc all what I need in my next stage.