|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 08/09/2009 at 10:30PM PDT, ID: 24639043 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: |
// Client2.cpp 2009-08-06
//
// Test driver for COM Adapter3 to access the Calculator DLL
//
#include <windows.h>
#include <objbase.h>
#include <iostream>
#include <iomanip>
using namespace std;
#include <atlbase.h>
#include <atldef.h>
#include <windef.h>
#include "ComAdapter3_i.h"
///////////////////////////// Interface code for accessing the COM Adapter ///////////////////////////////////////
int main()
{
// Initialize COM
HRESULT hr = 0;
LPUNKNOWN pServer = 0;
ICoCalc* calc = 0;
::CoInitialize(NULL);
// Tried this:
//PVOID sv = 0;
//Wow64DisableWow64FsRedirection(&sv);
hr = CoCreateInstance(CLSID_CoCalc, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (LPVOID*) &pServer);
if (FAILED(hr))
{
cout << "Failed to load server\n";
goto cleanup;
}
hr = pServer->QueryInterface(IID_ICoCalc, (LPVOID*)&calc);
if (FAILED(hr))
{
cout << "ICalc not found" << endl;
goto cleanup;
}
////////////////////////// Normal Application Code //////////////////////////////
cout << "\n\tCalcTest\n\n\n";
long a = 0, b = 0, c = 0;
while (cout << "Enter two integers or Q to quit: ", cin >> a >> b)
{
// COM keeps the function addresses in the VTable, makes virtual function calls
c = calc->Add(a, b); // a proxy layer could hide calc pointer
cout << "Sum = " << c << endl;
/// I modified Add to just: return 8 * sizeof(size_t);
/// It returns 32 or 64 to show what version of code is running in the "COM server"
cout << "\nClient calc: " << calc << endl;
cout << "Add: a: " << a << " &a: " << &a << endl;
cout << " b: " << b << " &b: " << &b << endl;
cout << " c: " << c << " &c: " << &c <<endl;
}
cleanup: // Cannot build a new ComServer until its usage count is zero.
if (calc)
hr = calc->Release();
if (pServer)
hr = pServer->Release();
CoUninitialize();
return hr;
}
// CoCalc.cpp : Implementation of CCoCalc
//
// Test program with local Add function representing code that would be in 32-bit DLL.
// Calling the DLL will be easy after the 64-32 barrier is fixed.
//
// When launching Visual Studio, run as Administrator so that various build steps will work.
// Build ComAdapter3. Then build ComAdapter3PS by right-clicking on that Project name and selecting
// Project only > Rebuild on ComAdapter3PS.
//
// Next, go to Client3 directory and run COPY.BAT from a command line window. It copies some generated files.
// I like keeping the client and server separated.
// Then build the client3 program and run it.
// Be careful to check that client is 64-bits and Adapter is 32-bits. Test shows 64-bit Adapter is loaded, matching the
// bit-ness of the client. I need to turn off the direct matching and access the 32-bit version.
// The code is basically correct, just missing the magic instructions to override that mapping.
// Building both Client and Adapter in 32 or 64-bit mode shows correct 32 or 64 output.
#include "stdafx.h"
#include "CoCalc.h"
#include <cstddef>
#include <cstdlib>
// CCoCalc
STDMETHODIMP CCoCalc::Add(LONG a, LONG b)
{
long c = a + b;
c = sizeof(size_t) * 8; // report 32-bit or 64-bit version instead of sum to prove the 64 to 32 call works
return c;
}
|
Advertisement