|
STDMETHODIMP CTryoutATL::ConcatenateString(long count, BSTR *ReturnVal)
{
// TODO: Add your implementation code here
BSTR outputTempString;
BSTR outputString = new OLECHAR[30];
BSTR tempString = new OLECHAR[30];
swprintf(tempString,L"The KILLER ");
BOOL bFirstTime = TRUE;
for(long i =1; i < count ; i++)
{
BSTR tempString = new OLECHAR[30];
swprintf(tempString,L"This Ilanthendral kills %ld\n",i);
outputTempString = new OLECHAR[30*i];
if(!bFirstTime)
{
wcscpy(outputTempString,outputString);
wcscat(outputTempString,tempString);
}
else
wcscpy(outputTempString,tempString);
bFirstTime = FALSE;
delete [] outputString;
delete [] tempString;
outputString = outputTempString;
}
*ReturnVal = outputTempString;
return S_OK;
}
for thendral
|
|
|
|
|
- The outer
tempString will always leak one allocation. - If
count == 0, outputString will not be deallocated - If
count == 0, outputTempString will never be assigned to, so you'll return an indeterminate value
In addition - these aren't valid BSTR s. BSTR s contain more information than just raw characters (for example, string length), so should always be allocated using SysAllocString , SysAllocStringByteLen or SysAllocStringLen and deallocated using SysFreeString .
I'd suggest you read the documentation for CComBSTR or _bstr_t and then use one of them rather than BSTR . These BSTR wrappers make BSTR management much easier. BSTR management much easier.
|
|
|
|
|
Hello,
Has anyone any experience with Forward Referencing in Attributed COM programming in Visual Studio 2005 ?
In Visual Studio 2003, I was using the following to forward reference an interface.
[export] __interface IMyDefinitions;
This basically used to insert a line in the IDL file "__interface IMyDefinitions", for forward referencing.
But it no longer works in Visual Studio 2005. No such line is inserted, and hence it fails during IDL compilation.
Thanks & Regards,
Arun Gupta
|
|
|
|
|
I want to use the set and map templates for fast log(n) search (using lower_bound, equal_range).
To do that i have to ensure that my containers are sorted.
Now here is my first question:
Do i have to call sort myself or does the containers sort themself?
If they sort themselves: When do they sort? Upon insertion (When i call insert(), etc)? or upon access (When i call lower_bound(), equal_range(), etc)? or upon deletion (erase(), etc)?
If they do not sort themselves: When should i sort? After insertion or before search()?
Wich sort function should i use? (sort or stable_sort())?
Now here is my second question:
I am using the set and map to contain pointers to my "GameObject" class (such as "wall", "room", "enemy" etc) - so how should i define a function-object or function to sort them out? Thought of sorting them by memory adress (bad idea)? And is there a default sort function for pointers?
/Jimmy
-- modified at 18:29 Monday 17th September, 2007
|
|
|
|
|
JimmyAberg wrote: Do i have to call sort myself or does the containers sort themself?
The containers keep themselves ordered.
JimmyAberg wrote: If they sort themselves: When do they sort?
On insertion
JimmyAberg wrote: I am using the set and map to contain pointers to my "GameObject" class (such as "wall", "room", "enemy" etc) - so how should i define a function-object or function to sort them out? Thought of sorting them by memory adress (bad idea)? And is there a default sort function for pointers?
By default, pointers used as keys will be sorted on address.
As for what sort function to use...well, what's the key? What attribute of your class are you going to use to look for an object? Name? Unless you can work that out, you might just as well use a std::vector to hold your objects.
Anyway - the function object should be defined like this (the bits in italics should be replaced by your own code):
struct YourOrderingFunction : public binary_function <KeyType, KeyType, bool>
{
bool operator()(const KeyType& _Left, const KeyType& _Right) const
{
return true if _Left is less than _Right;
}
};
PS - if you're doing a lot more lookups than insertions, you may find that you get better performance using a sorted std::vector that you search with std::lower_bound , std::equal_range or std::upper_bound .
PPS - if you have multiple keys, do yourself a favour and look at the Boost Multi-Index Containers[^].
|
|
|
|
|
I am having a issue with tab order for controls in a WTL dialog. The dialog in which controls are present is a child dialog which sits in a parent dialog. I've tried using the tab order layout but that is of no use.
Can anybody help me on this?
Thanks in advance.
Sam
|
|
|
|
|
Hi all
I have prepared an MMC..i have to set image for scope pane item and as well as same image for items shown in resultpane...so what functions shuld i use...
plzz help me its very urgent...
thax in advnace
|
|
|
|
|
Hi All
I have to add comboboxes in a listcontrol while initializing a dialog containing that list control.if anyone can expalin using some code ..how to perform this..this wud me very helpful to me....thanks to all in advance..
|
|
|
|
|
I have made a toolbar for a website and what i want is when the user login's in the website with a username and password i want to establish a database connection to MYSQL database and execute query for retrieving data.
Can anyone give me the code. I am USING WIN32 and NOT MFC.
Thanks in advance.
Dhiraj
Dhiraj Kumar Saini
|
|
|
|
|
I'd suggest you look at the appropriate MySQL documentation:
Those should tell you how to connect to a MySQL database.
|
|
|
|
|
thanks for the link you gave me for the tutorial.
I am able to connect to MYSQL database from my win32 application and also able to query the database.
Thanks for your help.
Dhiraj
Dhiraj Kumar Saini
|
|
|
|
|
hi
i am working with VS2003 and i got a problem with accessing to list member functions.
i have :
<br />
class company<br />
{<br />
public:<br />
CString comapany_name;<br />
int Number;<br />
list<worker> work;<br />
<br />
public:<br />
time_of_work(int ID);<br />
company(void);<br />
virtual ~company(void);<br />
}<br />
and
class worker
<br />
{<br />
public:<br />
CString name;<br />
int ID;<br />
int hours<br />
<br />
public:<br />
get_name(int ID);<br />
worker(void);<br />
virtual ~worker(void);<br />
}<br />
when i try to get the member function from the a company iterator that don't work:
<br />
list<company>::iterator comp;<br />
comp->..... it give me just a list of company methods and variables<br />
and if i try the dot('.')
<br />
comp. i can get {iterator, operator+,operator-,operator*,operator= }<br />
how can i get the list of the member functions ?
|
|
|
|
|
Your question isn't clear - for which class do you want a list of methods?
|
|
|
|
|
Can a Key in a map contain the combination of two variables?
Tough Time Never last, but Tough People do.
|
|
|
|
|
I think yes! through pair
|
|
|
|
|
Can you be more specific?
Steve
|
|
|
|
|
Key type could be a set of variables inside a structure or class.
valikac
|
|
|
|
|
I am able to find whether the webpage is a document object or not if it is then i want to retrieve the complete source code of the webpage and store it in a CString, Which interface to query and which function to use.
I want this thing to happen in BeforeNavigate2 of DWebBrowserEvents2.
Thanks in advance.
Dhiraj
Dhiraj Kumar Saini
|
|
|
|
|
Hi,
I want to create an IE plug-in where whenever a download dialog is expected, the file is downloaded automatically to a specified folder - the dialog should should not appear.
Has anyone worked on something similar? Is such a thing work be possible to do w/out extensive COM/IE/ATL/OLE knowledge?
I am somewhat familiar with C++ & COM/ATL/OLE concepts.
From the MSDN docs, I also know that I just need to create a COM object which implements a couple of interfaces and register it.
But, am absolutely clueless where to begin & how to get to that. (Never used the Visual Studio)
Any helpful pointers plz ?
Thanks,
-pk
|
|
|
|
|
|
You can use IMoniker for downloads files and IBindStatusCallback for accepts information on an asynchronous bind operation.
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
// CestDLHandler
CestDLHandler::CestDLHandler()
{
m_lUid = 0;
}
STDMETHODIMP CestDLHandler::Download(IMoniker* pmk,
IBindCtx* pbc,
DWORD dwBindVerb,
LONG grfBINDF,
BINDINFO* pBindInfo,
LPCOLESTR pszHeaders,
LPCOLESTR pszRedir,
UINT uiCP )
{
traceFerruccio(_T("IMoniker %p CestDLHandler %p \n"),pmk, this);
HRESULT hr;
//Stream will be released in the BSCB OnDataArrival
IStream *pstm;
//Attempt to create our BindStatusCallBack
WBBSCBFileDL *filedl = NULL;
//Returns a NonAddRef pointer to a new BSCB
//AddRef is called on this BSCB during a successfull call
//to RegisterBindStatusCallback
if(WBCreateBSCBFileDL(&filedl) != S_OK)
{
return E_FAIL;
}
//Init the BSCB
m_lUid++;
filedl->InitByUser(m_lUid, this, pszHeaders, NULL);
IBindStatusCallback *pPrevBSCB = NULL;
hr = RegisterBindStatusCallback(pbc,
reinterpret_cast<ibindstatuscallback*>(filedl), &pPrevBSCB, 0L);
/*
Exception to the rule
RegisterBindStatusCallback return E_FAIL
Cause: Content_Disposition header returned from a server
in response to a file download via a post or ,..
Example: downloading attachements from Hotmail, Yahoo, ...
Unfortunately, due to no documentation regarding an E_FAIL return,
and more specifically, regarding RegisterBindStatusCallback internal workings,
I had to resort to using RevokeObjectParam on the previous BSCB and in my
implementation of BSCB, relay certain calls to the previous BSCB to make DL work.
I do not know if this is a bug or done intentionaly.
*/
/*
KB article http://support.microsoft.com/default.aspx?scid=kb;en-us;274201
Notifies the client application that this resource contained a
Content-Disposition header that indicates that this resource is an attachment.
The content of this resource should not be automatically displayed.
Client applications should request permission from the user.
This value was added for Internet Explorer 5.
*/
if( (FAILED(hr)) && (pPrevBSCB) )
{
//RevokeObjectParam for current BSCB, so we can register our BSCB
LPOLESTR oParam = L"_BSCB_Holder_";
hr = pbc->RevokeObjectParam(oParam);
if(SUCCEEDED(hr))
{
//Attempt register again, should succeed now
hr = RegisterBindStatusCallback(pbc,
reinterpret_cast<ibindstatuscallback*>(filedl), 0, 0L);
if(SUCCEEDED(hr))
{
filedl->m_pPrevBSCB = pPrevBSCB;
//Need to add ref to our DLMan
filedl->AddRef();
pPrevBSCB->AddRef();
filedl->m_pBindCtx = pbc;
pbc->AddRef();
}
}
}
if(SUCCEEDED(hr))
{
hr = pmk->BindToStorage(pbc, 0, IID_IStream, (void**)&pstm);
}
else //add right-click "save target as" support
{
delete filedl;
USES_CONVERSION;
LPOLESTR data = NULL;
pmk->GetDisplayName(pbc, NULL, &data);
TCHAR* myUrl = OLE2T(data);
HRESULT hr;
hr = URLDownloadToFile(NULL,myUrl,NULL,0,NULL);
if ( SUCCEEDED(hr) )
{
}
else
{
LPTSTR lpszErrorMessage;
if ( FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, hr,
MAKELANGID ( LANG_NEUTRAL, SUBLANG_DEFAULT ),
(LPTSTR) &lpszErrorMessage, 0, NULL ))
{
//sMsg.Format ( _T("Download failed. Error = 0x%08lX\n\n%s"),
// (DWORD) hr, lpszErrorMessage );
LocalFree ( lpszErrorMessage );
}
else
{
//sMsg.Format ( _T("Download failed. Error = 0x%08lX\n\nNo message available."),
// (DWORD) hr );
}
}
}
return hr;
}
History
|
|
|
|
|
Dear all,
I am writing a CMyFileDialog class inherited from CFileDialogImpl. When I choose some special file,a checkbox will show at this time. Now the question is I don't know how to create a dynamic checkbox. or is there other way to realize this function??? Waiting for the answer...;) Thanks!!!
Anna
^_^
|
|
|
|
|
Hi Anna,
Use the code
1) Get the handle of the check box control
HWND hwnd=GetDlgItem(IDC_CHECKNOX1);
2) Call the enable window function and pass TRUE if you want it to be
visible otherwise make it false.
hwnd->EnableWindow(FALSE);
OR
hwnd->EnableWindow(TRUE);
Hope this solves your problem.
Do reply
Dhiraj
Dhiraj Kumar Saini
|
|
|
|
|
hi,Saini
Thanks for your help. I use "this->ShowWindow(TRUE)" to make the checkbox show. But does hWnd have the function "EnableWindow()"??? It seems that it only has one variable...
|
|
|
|
|