|
Hi, all
In Atl project ,how can I return the user define type?
For example , I have define a Struct ,and I want to return the Struct type in a function, and I plan to utilize the return Struct type in VB through the com. What should I do ? I have try some ways ,but failed.
Another similar problem. I have two ATL Object in my Atl
project , Teacher and Student . And student is a private property of Teacher ,now I want to construct a function in Teacher to return the Student property .How should I do ?
Sincerely ask for help. Who can tell me how to do , or give me some similar source code which resovle the above problems .
I'll appreciate it .
Regards.
|
|
|
|
|
In the IDL file do the following:
typedef struct
{
int x;
int y;
} POINT;
interface IMyInterface : IUnknown
{
[propget, helpstring("property Point")] HRESULT Point([out, retval] POINT *pVal);
Note that the iterface inherits from IUnknown (Custom interface) and not from IDispatch (Dual interface).
Goodluck,
Dudi
|
|
|
|
|
And how can I construct the CStudent object in CTeacher.
Details as follows.
In the construction function of the CTeacher :
CTeacher()
{
IStudent * m_student =new CStudent();
return;
}
There are some compiler errors. It says that the CStudent cannot instantiate abstract class due to following members:QueryInterface,AddRef,Release.
How should I do to resolve the problem.
thx.
Regards.
|
|
|
|
|
You cannot create a com object by using new.
Use CComObject instead:
CComObject<CStudent> *m_student;
HRESULT hr = CComObject<CStudent>::CreateInstance(&m_student);
|
|
|
|
|
Hi, all
Some problems about ATL Com:
1.I have create two ATL Object: CStudent and CTeacher .
The simple source code listed as follow: (some code auto generated by ATL have been skiped)
class CStudent
{
private:
long m_age;
public:
CStudent():m_age(10)
{
}
//...other code auto generated by ATL
};
class CTeacher
{
private:
IStudent* m_aStudent;
public:
CTeacher()
{
//create an instance of the com
CoCreateInstance(CLSID_Student,NULL,CLSCTX_ALL,IID_IStudent, (void**)&m_aStudent);
}
//...other code auto generated by ATL
}
2.Then I add a "IStudent * OneStudent" property for ITeacher ,to access the m_aStudent.
The implemention of the property are listed as below:
STDMETHODIMP CTeacher::get_OneStudent(IStudent *pVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
*pVal = * m_aStudent;
return S_OK;
}
STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
*m_aStudent = *newVal ;
return S_OK;
}
3.Now I type some VB code to test the com ,but some compiler errors occurrs.
VB Code:
Dim s As Student
Dim t As New Teacher
s = t.OneStudent
the last sentence "s = t.OneStudent" have compiler errors.
Errors:function or interface marked as restricted ,or the function use an Automation type not supported in Visual Basic
I guess the errors caused by the type dismatch between IStudnet and CStudent.But I did not know how to resolve it .
So who can tell me how to return the m_aStudent that can be supproted in vb??
thx.
Regards.
|
|
|
|
|
In VB you should write
set s = t.OneStudent.
Now, you don't support 'get' function but 'put' function.
This is why VB send you that error.
Add the following:
STDMETHODIMP CTeacher::get_OneStudent(IStudent **pVal)
{
// put your code
return S_OK;
}
you should change the IDL file, as well.
Goodluck,
Dudi
|
|
|
|
|
1. At a late stage in the evolution of my MDI CFormView based GUI development I am told that my GUI must access a database. Now i didnt build in db support at the start of the project. Surely this doesnt mean I start over again?
2. I have some books that talk of DAO and MFC. It was mentioned I should use ADO but I cannot find any thing about it - like samples etc.
3. In a sample project I have using DAO, they have to use the Class Wizard to create a new recordset class derived from CDaoRecordSet. The CW then points you to the mdb file on the disk and you choose tables etc. Now I'll be needing to do this stuff dynamically, ie. if the user specifies a db name during runtime, I need to automate the process of creating the recordset class. My database is a flat file with the fields being keywords, and the rows being the records and the entries in the "matrix" being the values of these keywords.
according to this sample project -"the CW will prompt you for which table(s) to include in the record set class. The CW then creates the recordset and you see that there is a member variable in this class for each column in the table you selected. "
So here my question is, I will be doing this for diffferent databases with different # of fields, and how do I create the recordset in code instead of manually through the CW.
I am just starting to investigate the notion of databases so I will have tons more questions, and hope these above aren';t confusing. I really appreciate your response,
thanks,
ns
|
|
|
|
|
|
You know, rihjt after I posted these questions, I got the brilliant idea of checking out CP and viola! a wealth of info answering some of my questions, though more will follow shortly without a doubt. SO thanks!! The rest of the web seems to have nothing with a google search of database, ADO and MFC.....unless i'm doing a poor search.
Thanks,
ns
|
|
|
|
|
I'm trying to add HTMLHelp support to my application. I can create HTMLHelp and have the proper libraries linked in but I don't understand how to set the HH_POPUP parameters for use in the HtmlHelp() function.
In my OnHelpInfo(HELPINFO* pHelpInfo) event, I normally use...
AfxGetApp()->WinHelp(pHelpInfo->dwContextId, HELP_CONTEXTPOPUP);
I'm replacing it with...
HH_POPUP popup;<br />
HtmlHelp(GetSafeHwnd(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD)&popup);
How should I set the values for popup ?
|
|
|
|
|
i can use isapi op a Cookie,but,how i can op a session?
please help me,
ths!!!
if you have code,tell me!
ths again
|
|
|
|
|
I guess that depends on what "op" means?!...
"After all it's just text at the end of the day. - Colin Davies
|
|
|
|
|
Is it possible to get the main window which associated with an instance handle? Or there's no such association?
Any help will be personally blessed!
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
|
Man, one thing I don't get: WHAT should I compare???
I've HINSTANCE which ShellExecute() returned.
GetWindowThreadProcessId() gives me 2 values: threadID + processID.
Is the thread/processID == the HINSTANCE I've (with some casting maybe)?
OR ELSE??? I simply what to figure which HWND belongs to the HINSTANCE I hold.
Enlighten me plz...
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
BlackSmith wrote:
I've HINSTANCE which ShellExecute() returned.
Big Mistake!!!!!
MSDN says :-
The return value is cast as an HINSTANCE for backward compatibility with 16-bit Microsoft® Windows® applications. It is not a true HINSTANCE, however.
You need to be using ShellExecuteEx using which you can get the thread id and the process id of the process which you can then compare with the ids you have obtained.
Read this article for info on using ShellExecuteEx :-
http://www.codeproject.com/system/newbiespawn.asp
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
1) I know how to use the Add Member Variable Wizard to create a variable and associate it with a control, but how do you remove it?
Currently I am forced to manually track down every reference to the variable in the code and remove it.
A principle of good desing is that when ever you include an operation you should also include its opposite. If I can add the variable automatically I should also be able to remove or rename it automatically. So I am assuming that editing the source code is not the best method of removing a variable.
Is there an Remove Member Variable Wizzard or something similar?
2) UpdateDate(TRUE/FALSE) WTF?????
Was someone on crack when they came up with this. I just got done reading Code Complete published by Microsoft Press and this function violates just about every principle of good design. Specifically.
a) Each function should have a single well defined purpose. UpdateData() is cleary two separate operations, UpDateData() and UpdateControls() shoved into the same function.
b) The Function Name Should acurately describe everything the function does. A correct name would be UpdateDataOrUdateControls(); This is an ugly name but its an ugly function.
c) Well written code is self documenting. UpdateData() and UpdateControls() have straight forward meanings. What does UpdateData(FALSE) mean.
What was their reasoning? Am I missing something?
|
|
|
|
|
Raskolnikov wrote:
Is there an Remove Member Variable Wizzard or something similar?
What version of VC aare you using? 6 or 7?
I know with with VC6 you can use the class wizzard and select the variables tab you can delete your variables there. If you added a member variable your self you can use the class window. Right click and select delete.
Raskolnikov wrote:
c) Well written code is self documenting. UpdateData() and UpdateControls() have straight forward meanings. What does UpdateData(FALSE) mean.
What was their reasoning? Am I missing something?
Um, did they have any reasoning with that?
From my experience, it's best to not even bother with UpdateData() and just use control variables. It's just to much of a hassle IMO . Here's a good link that will explain better than what I could do.
http://www.codeproject.com/cpp/avoidupdatedata.asp[^]
Cheers
|
|
|
|
|
Thanks, I will definately read that article.
|
|
|
|
|
Raskolnikov wrote:
2) UpdateDate(TRUE/FALSE) WTF?????
Raskolnikov wrote:
What was their reasoning? Am I missing something?
Nope, MFC sucks hairy donkey balls. But, it used to be worse... And it's still better than nothing. (although you may want to give this new WTL thing a look; i've heard it sucks less)
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
What is WTL, I might have to add it to my list of things to learn.
|
|
|
|
|
|
1) You should in any case learn to add and remove your own member variables. The wizard blows up from time to time, and if that is when you start trying to learn how to do things by hand, you'll be stuffed.
2) UpdateData is a screwy mechanism, as has been said. Do not use it.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
I already fluent in C++ so manually adding and removing member variables is no problem, I was just looking for a more elegant solution.
I will definately heed the warning about avoiding UpdataData.
I think what happens with serialized API is all the bad design choices get propagated from one version to the next.
|
|
|
|
|
Any one know how to get to the "variables tab" in VC 7.
The class wizard has gone missing and I want to be able to quickly delete (or better yet rename) misspelled variable without mucking with the source code.
|
|
|
|