|
Having found the VB files that used this interface to call C++ implemented COM I see:
An object declared usaing the tlb namespace:
Dim WithEvents m_objController As CONTROLLERLib.CoController
Then in a sub procedure I can type the namespace CONTROLLERLib and on typing the . after it the intelli-sense displayes all the enumerated values from the . idl file.
I can then type:
CONTROLLERLib.CoolingSystem = CONTROLLERLib.System2
though I don't think this correct and I'm not set up to try actually run antything
I also came across the enum (CoolingSystem) used in a VB Sub declaration:
Private Sub m_objController_TemperatureChanged(ByVal ErrorCode As Long, ByVal System As CONTROLLERLib.CoolingSystem, ...
Maybe it's something to go on.
|
|
|
|
|
Thanx budy..
it works..
but i dont want it to add into COM property..
so only above declaration got useful
|
|
|
|
|
Make sure the enum is in the 'library' part of the IDL file: I just built and registered a little COM DLL with this IDL:
import "oaidl.idl";
import "ocidl.idl";
[
uuid(AB41E782-D178-47AA-950A-91406234E0A5),
version(1.0),
helpstring("aa 1.0 Type Library")
]
library aaLib
{
importlib("stdole2.tlb");
typedef enum LANG{ HIN,ENG,MAR,JAP,CAN }LANG;
};
Opening it in the Object Browser in Word's VBA IDE showed the enumerated type and the enumerations.
HTH!!!
|
|
|
|
|
I want to retrieve information from secured(requires user name and
password) web service. I can connect it with .NET 2.0 web service using
NetworkCredentials class. But when I tried it with C++, I cannot even
send the username and password. The code doesn't send any authentication information. So the
server send HTTP 401 Authectication error back.
I'm searching web. I read and tried all I found.
I use VS2008 with ATL Server Library & tools.
thanx.
|
|
|
|
|
|
class CSampleBasicAuth : public CBasicAuthObject, public IAuthInfo
{
void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo)
{
CBasicAuthObject::Init( pSocket, pAuthInfo );
}
bool Authenticate(LPCTSTR szAuthTypes, bool bProxy)
{
username = _T("user");
password = _T("password");
return CBasicAuthObject::Authenticate( szAuthTypes, bProxy );
}
HRESULT GetPassword(LPTSTR szPwd, DWORD* dwBuffSize)
{
if (CopyCString( password, szPwd, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetUsername(LPTSTR szUid, DWORD* dwBuffSize)
{
if (CopyCString( username, szUid, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetDomain(LPTSTR szDomain, DWORD* dwBuffSize)
{
ATLASSERT(false);
return S_OK;
}
CString username;
CString password;
};
Service::CService *srv = new Service::CService();
CAtlHttpClient &httpClient = srv->m_socket;
CSampleBasicAuth *basicAuth = new CSampleBasicAuth();
httpClient.NegotiateAuth(true);
httpClient.AddAuthObj( ATL_HTTP_AUTHTYPE_BASIC, basicAuth, basicAuth );
srv.doSomeThing()..
what's wrong ?
thanks
|
|
|
|
|
Does the web service accept basic authentication or does it require some other authentication?
[edit]I'd recommend using Fiddler[^] to spy on the HTTP traffic[/edit]
|
|
|
|
|
It's solved. Thank you.
CSampleBasicAuth *basicAuth = new CSampleBasicAuth();
changed
CSampleBasicAuth basicAuth;
if authentication obj is a pointer,
inline bool CBasicAuthObject::DoBasicAuthenticate() throw()
{
bool bRet = false;
ATLASSUME(m_pClient);
ATLASSUME(m_pAuthInfo);
.
.
thanks for your help.
|
|
|
|
|
I have a Dialog, inheriting from CDialogImpl , which contains a CListViewCtrl with three columns. In order to get the list items ordered correctly a custom sort function is used. It is in my handler for LVN_COLUMNCLICK< (Clicking a column header) that that the column header has the triangular bitmap indicating sort direction set.
On creation of the dialog, without the workaround shown below, no sort direction arrow appears on the header. I then have to call the LVN_COLUMNCLICK handler (see code) from OnInitDialog to force a sort of the first column in the order that my LVN_COLUMNCLICK handler sets the sort order triangular bitmap in the column header.
LRESULT CPortsDlg::OnInitDialog(UINT , WPARAM , LPARAM , BOOL& )
{
...
int idCtrl = 0;
NMLISTVIEW nmlv;
nmlv.iSubItem = 0;
BOOL bHandled = FALSE;
LPNMHDR lpNMHDR = reinterpret_cast<LPNMHDR>(&nmlv);
OnLvnColumnclick(idCtrl, lpNMHDR, bHandled);
return 0;
}
This doesn't seem right; am I missing some feature that will ensure that upon creation a particular list column is sorted (using my custom sort) in, say, ascending order with the appropriate column header bitmap displayed to indicate this?
LRESULT CPortsDlg::OnLvnColumnclick(int , LPNMHDR pNMHDR, BOOL& )
{
if(!::IsWindow(m_hWnd))
{
return 0;
}
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
HDITEM HeaderItem;
HeaderItem.mask = HDI_FORMAT;
CHeaderCtrl HeaderCtrl = m_ListViewCtrl.GetHeader();
if(!::IsWindow(HeaderCtrl.m_hWnd))
{
return 0;
}
int nColumnCount = HeaderCtrl.GetItemCount();
for(int nSelectedColumn = 0; nSelectedColumn < nColumnCount; nSelectedColumn++)
{
HeaderCtrl.GetItem(nSelectedColumn, &HeaderItem);
HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
if(nSelectedColumn == pNMLV->iSubItem)
{
m_SortAscending = (m_CurrentSortItem != pNMLV->iSubItem) ? true : !m_SortAscending;
HeaderItem.fmt |= m_SortAscending ? HDF_SORTUP : HDF_SORTDOWN;
}
HeaderCtrl.SetItem(nSelectedColumn, &HeaderItem);
}
m_CurrentSortItem = pNMLV->iSubItem;
m_ListViewCtrl.SortItems(SortFunc, (DWORD_PTR)this);
return 0;
}
|
|
|
|
|
It doesn't seem unreasonable to me that you have to tell the control how it's sorted - I suspect that setting HDF_SORTDOWN or HDF_SORTUP on the relevant column and calling m_ListViewCtrl.SortItems would be sufficient - if that's the case, maybe you should refactor the header flag setting and control sorting into a separate function, so it could be called from OnInitDialog rather than calling the OnClick handler?
[edit]Maybe CSortListViewCtrl will do some of the sorting tasks for you, simplifying the overall job?[/edit]
|
|
|
|
|
Stuart,
I've done a test using CSortListViewCtrl (which I didn't know about) instead of CListViewCtrl . It seems that simply calling SetSortColumn(0) both makes my handler for LVN_COLUMNCLICK redundant and removes the need to call it from InitDialog. I haven't tried this with a custom sort yet but can see I will need to call SetColumnSortType(0, LVCOLSORT_CUSTOM) .
Much neater.
Thanks.
|
|
|
|
|
Hi,
I got code for ICopyHook interface which traps FOLDER's CUT,COPY, PASTE operation but I want the same thing for Word file. Is there any way by which we can trap the CUT, COPY and PASTE operation for WORD file.
Thanks
SNI
|
|
|
|
|
Do you mean a cut, copy or paste performed within Word? If so, I don't think so - the documentation[^] seems pretty clear that an ICopyHook handler is a shell extension, so would form part of Explorer, and that it only gets to approve/disapprove operations on folders or printers.
|
|
|
|
|
|
Hi Experts,
I m bit confused about ATL COM applications..and DLL
As I have already developed and using DLL(MFC/NON MFC) created in VC 6.0.
So Is there any advantages if I covert this into ATL COM. what are they??
And if I m capable of doing so..i.e. Converting DLL(MFC/NON MFC) into ATL COM application
then Whats type of care must have to be taken???
Like ...........
1> Global and local variable .or
2> Public/protected members of CLASS .or
3> Exported functions of DLL
plz guide me..and clear my confusion....
Thanx in advance..
Victory
modified on Wednesday, January 14, 2009 2:16 PM
|
|
|
|
|
Using COM makes it easier to use your DLL with languages other than C++, for example VBA or VB.
vijay.victory wrote: As I have already developed and using DLL(MFC/NON MFC) created in VC 6.0.
So Is there any advantages if I covert this into ATL COM
If it ain't broke, don't fix it.
vijay.victory wrote: And if I m capable of doing so..i.e. Converting DLL(MFC/NON MFC) into ATL COM application
then Whats type of care must have to be taken Like ...........
1> Global and local variable .or
2> Public/protected members of CLASS .or
3> Exported functions of DLL
Sounds like you need to learn about COM first...
COM defines a mechanism by which you can define and use objects in a (relatively) language independent manner. You expose objects through interfaces (a.k.a. pure abstract classes). Globals and locals aren't so much of an issue, as functionality is exposed in an OO way. Public/protected class members aren't an issue, as you only expose methods that implement (public!) interface methods. Exported functions aren't an issue - the COM specification tells you what functions to export (DllGetClassObject and DllRegisterServer )
|
|
|
|
|
Hello,
My task is to encrypt the body of the e-mail and send to receiver.
On receiver side, decrypt and display the content.
The input to my encryption algo is unsigned char.
So I did like below
Sender=>;
get_Body() => BSTR => UCHAR => ENCRYPT => ENCRYPT_UCHAR => BSTR => put_Body()
Receiver =>;
get_Body() => BSTR => ENCRYPT_ UCHAR => DECRYPT => BSTR => put_Body
The problem I am facing is, the ENCRYPT_ UCHAR of sender is different from receiver.
I tried to convert in the sender side, by converting the BSTR to ENCRYPT_UCHAR before put_Body..the data is fine.
I am using W2A and A2W for conversion.
Thanks in advance
SAI
|
|
|
|
|
It's probably not wise to treat an encrypted message as a character stream - I would suggest you treat it as a stream of bytes instead - which, to be honest, is what unsigned chars usually represent in C/C++.
In fact, I wouldn't bother to convert from BSTR to unsigned char using a charset->charset mapping. I would just treat the BSTR as a set of bytes (aka unsigned chars). You can do this as shown in this sample program:
#include <windows.h>
#include <oleauto.h>
#include <iostream>
#include <iterator>
#pragma comment(lib, "oleaut32")
int main(int argc, char** argv)
{
const wchar_t* s = L"Hello World";
BSTR bs = SysAllocStringLen(s, lstrlenW(s));
unsigned char *byteStream = (unsigned __int8 *)bs;
ULONG byteCount = SysStringByteLen(bs);
std::cout << "byteCount = " << byteCount << std::endl;
std::cout << "bs (in bytes) = ";
for(unsigned char * p=byteStream;p!=byteStream+byteCount;++p)
std::cout << std::hex << (int)(*p) << " ";
std::cout << std::endl;
}
This shows the bytes that make up the BSTR . You can then encrypt that set of bytes.
If you are returning a BSTR because it's an easy to use container, you can create a BSTR from a set of bytes as follows:
unsigned char *encryptedByteStream;
ULONG encryptedByteCount;
BSTR outputBS = SysAllocStringByteLen(encryptedByteStream, encryptedByteCount);
HTH!!
|
|
|
|
|
Hello,
Thanks for your reply..
I am getting the below error on adding the source code.
initializing' : cannot convert from 'unsigned __int8 *' to 'unsigned char *'
Could you please suggest me to solve this.
Thanks
|
|
|
|
|
Whoops - there was a typo - change
unsigned char *byteStream = (unsigned __int8 *)bs;
to
unsigned char *byteStream = (unsigned char *)bs;
Interestingly, I don't get that error with VC++ 2003, 2005 or 2008 - which compiler are you using - VC++ 6?
|
|
|
|
|
Hi, it seems that only I post questions around here, not a happy site
However, here I am having problems again. This time I get to play around with dialogs and controls guided by article series from Michael Dunn called "WTL for MFC programmers and something".
The problem is I can't add map entry
ATL_MSG_MAP(1)
MSG_WM_SETCURSOR(OnSetCursor_OK)
I'm getting errors:
"syntax error : missing ';' before identifier 'MSG_WM_SETCURSOR'"
"'ATL_MSG_MAP': identifier not found"
"'OnSetCursor_OK' : undeclared identifier"
I'm on WinXP using VS2008
Thanks in advance
|
|
|
|
|
I think that should be ALT_MSG_MAP - A<span style="font-weight: bold;">LT</span> , not A<span style="font-weight: bold;">TL</span> . You'll need to #include atlwin.h .
|
|
|
|
|
I already included atlwin.h in stdafx.h!
Don't quite understand your replay "I think that should be ALT_MSG_MAP - ALT, not ATL"?
Anyway big thanks to you!
|
|
|
|
|
You typed "ATL_MSG_MAP" in your original message. That symbol isn't in ATL, but ALT_MSG_MAP is, i.e. I think you made a typo at some point.
|
|
|
|
|
Need your help again, this time it's about adding notify handler for LVN_ITEMCHANGED message which is sent from listview ctrl.
NOTIFY_HANDLER_EX(IDC_LIST,LVN_ITEMCHANGED,OnListItemchanged)
I've included atlcrack.h but still get complaints?
I know that I'm trying to use code for WTL 7/7.1 while I have WTL 9 installed on VS2008 but I'm stern to go trough the series of articles here on CP by Dunn.
And sorry if I'm a pain to you
|
|
|
|