C++??C#??以????t??????
???????????? ???????[ 2014/1/23 9:28:24 ] ????????C++ C#
??????????????????????????????????????????????????????????????????μ?????????ε??e??
???????????????????ProgId????????????????COM???????ATL???????????????????‘????’???????????????????????????‘????’???????????????????
::CoInitialize(NULL);
const OLECHAR lpszProgID[]=OLESTR("xxxxxxx.xxxxxxx"); //ProgID
CComPtr m_NetCustomer;
HRESULT hr = m_NetCustomer.CoCreateInstance(lpszProgID);
if(SUCCEEDED(hr))
{
const LPCOLESTR szMember=OLESTR("OnCreate");
VARIANT v;
v.vt = VT_I4; v.lVal = 1024;
hr = m_NetCustomer.Invoke1(szMember??&v);
if(SUCCEEDED(hr))
{
}
}
::CoUninitialize();
???????????????????????д?????????????????
???????????C++????????????и????????????????????
????2. ??? ?????????
??????????????????????????????ε?????????????????????????????????????????????????????У????????????????????????????????????????????????????????????????????????????????ó?????????и????????????????????????????λ??????????
???????????????????????????????????????????????????·?????dll????????????????????????????????????????????????????
??????????????????????? ?????????????????????????DLL?????????????????????????????????“?????????????????漰?????????”
???????????????鶼????????DLL??
??????????????????DLL??????????????????????????
????????????????????????????????????????????
????????????????????????????????????
??????????????????????
??????????????????????????
?????????????????????????????
?????????????C++???????????????????? ???????????????(????)????????????????á??????????????????ú?????????????????????????
???????????????????????o????????????????????????????????????JMP??CALL ???????????????в??????ЩPUSH???????????Щ????????濴????VC?е?α????
????__asm
????{//???麯????????????????????????????????
????mov eax??xxxxx //?????????
????mov ecx??xxxxx //this???
????call eax //????
????}
?????????????????????????????????????????????????????????????Щ?????
?????????????.NET??????????????????????????????麯?????????????????DLL???????е???ж?????????????????????????????????????????????????????棬??????????????????
?????????????????????????????????????????濪????ο??????????????????????????????????????????????????????????
???????????????????????DLL(AsmClassLibrary.dll)????????д????????Reflector ????????????в?????????????????????????????????????????????????????????????????漰??????????????????????????????????????????ó?????????????????С?
???????????????Marshal.GetDelegateForFunctionPointer?????
????????????????????????????д???????????????????????????????????????????????????
?????????????????????????????????????C#????麯??????á?
????????????????????????·??
???????????????????????????????????????
????A ???????????????????????ECX??
????B ???????????????????????CALL??
????C ?????????????C#???????
??????????????????????????к???????????????????
???????????????????this????????????????????У??????????C#?У?????????????????????this???????????????????C#???????????????C++?б?????????????????C++???????
???????this??? ??????????????????????????????????
???????????????
class CInterface
{
public:
virtual void test1( LPSTR p)
virtual void test2();
virtual void test3( int a);
};
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11