// IFirst_ATL
public:
STDMETHOD(AddNumbers)(/*[in]*/ long Num1, /*[in]*/ long Num2, /*[out]*/ long *ReturnVal);
};
#endif //__FIRST_ATL_H_
#include "Simple_ATL.h"
#include "First_ATL.h"
...
STDMETHODIMP CFirst_ATL::AddNumbers(long Num1, long Num2, long *ReturnVal)
{
// TODO: Add your implementation code here
// {
*ReturnVal = Num1 + Num2;
// }
return S_OK;
}
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\System32\stdole2.tlb#OLE Automation Reference=*\G{FAF439B7-3BF5-4284-8532-EE095728AC22}#1.0#0#..\Debug\Simple_ATL.dll#Simple_ATL 1.0 Type Library
Form=Form1.frm
...
Private Sub Command1_Click() Dim objTestATL As SIMPLE_ATLLib.First_ATL
Dim lngReturnValue As Long
Set objTestATL = New First_ATL objTestATL.AddNumbers 5, 7, lngReturnValue
MsgBox "The value of 5 + 7 is: " & lngReturnValue Set objTestATL = Nothing
End Sub
or
#include <iostream.h>
// You need to point this header file to the directory
// you placed the Simple_ATL project
#include "..\..\Simple_ATL.h"
// Copy the following from the Simple_ATL_i.c file
// from the Simple_ATL project directory
// NOTE: You can actually skip copying these if you want
// and just include the Simple_ATL_i.c file, I simply added
// it for clarity to show where these const variables are
// coming from and what they look like
#include "..\..\Simple_ATL_i.c"
/*
const IID IID_IFirst_ATL = {...};
const CLSID CLSID_First_ATL = {...};
*/
int main(int argc, char* argv[])
{
// {
// Declare and HRESULT and a pointer to
// the Simple_ATL interface
HRESULT hr;
IFirst_ATL *IFirstATL = NULL;
// Now we will intilize COM
hr = CoInitialize(0);
// Use the SUCCEEDED macro and see if
// we can get a pointer
// to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_First_ATL, NULL, CLSCTX_INPROC_SERVER, IID_IFirst_ATL, (void**) &IFirstATL);
// If we succeeded then call the AddNumbers
// method, if it failed
// then display an appropriate message to the user.
if(SUCCEEDED(hr))
{
long ReturnValue;
IFirstATL->AddNumbers(5, 7, &ReturnValue);
cout << "The answer for 5 + 7 is: " << ReturnValue << endl;
IFirstATL->Release();
}
else
{
cout << "CoCreateInstance Failed." << endl;
}
}
// Uninitialize COM
CoUninitialize();
// }
// printf("Hello World!\n");
return 0;
}