|
Hi,
I'm working on an ATL COM project. The most of the DLL's function is to retrieve and send objects with the software that uses it and do the required job(as in business layer of the 3-layer architecture in object oriented development).
I did have many obstacles while learning this strange library. But now all was gone. I'm good enough to develop what I thought at the beginning. But I have some questions about improving the quality of the written code. When accessing the DLL all code is simple enough to understand and develop. But when accessing an object within another object some strange stuff come in sight.
To explain it simply, I'm gonna give an example which I gave in my another question as well. Take the Course, Department and Student classes again.
Student have attributes as name, surname and these can be accessed with the following methods out of the DLL.
<br />
STDMETHODIMP CStudent::get_name(BSTR* pVal)<br />
{<br />
CComBSTR bstStr(this->name);<br />
*pVal=bstStr.Detach();<br />
return S_OK;<br />
}<br />
<br />
STDMETHODIMP CStudent::put_name(BSTR newVal)<br />
{<br />
_stprintf(this->name, _T("%s"), (LPCTSTR) newVal);<br />
return S_OK;<br />
}<br />
There is nothing strange in this code when accessing Student class from outside of the DLL as below in C#
<br />
Student s = new Student();<br />
s.name = "MyName";<br />
String s = s.name;<br />
But what if I send this class' instance to one of the methods of the Department class as below.
<br />
STDMETHODIMP CDepartment::processSomething(IStudent* std)<br />
{<br />
BSTR stdName;<br />
std->get_name(&stdName);<br />
...<br />
...<br />
return S_OK;<br />
}<br />
or when accessing an class' attribute which is another class.
<br />
...<br />
ICourse* course;<br />
std->get_course(&course);<br />
BSTR courseName;<br />
course->get_name(&courseName);<br />
...<br />
I mean defining variables and/or creating instances of the classes is taking long. I tried another way to make the code easier and shorter. First I define extra methods for each method to access the object's attributes simply as below.
<br />
STDMETHODIMP CStudent::get_name(BSTR* pVal)<br />
{<br />
*pVal = this->getName();<br />
return S_OK;<br />
}<br />
<br />
BSTR CPatient::getName()<br />
{<br />
CComBSTR bstStr(this->name);<br />
return bstStr.Detach();<br />
}<br />
<br />
STDMETHODIMP CStudent::put_name(BSTR newVal)<br />
{<br />
this->putName(newVal);<br />
return S_OK;<br />
}<br />
<br />
void CPatient::putName(BSTR newVal)<br />
{<br />
_stprintf(this->name, _T("%s"), (LPCTSTR) newVal);<br />
return bstStr.Detach();<br />
}<br />
Thus there is two way to access the required method. One for inside of the DLL and one for outside of the DLL. So that when accessing the member of this class within another class is so easy as below
<br />
STDMETHODIMP CDepartment::processSomething(IStudent* std)<br />
{<br />
CStudent* cstd = static_cast<CStudent*>(std);<br />
BSTR stdName = cstd->getName();;<br />
...<br />
BSTR courseName = cstd->getCourse()->getName();
...<br />
return S_OK;<br />
}<br />
Of course one can access the attributes changing them as public instead of private. But we don't want it, do we?
With ICourse the attributes and methods of the class cannot be accessed directly. To access CCourse must be used.
My questions are
*Is casting the ICourse to the CCourse with the static_cast appropriate?
*I searched the web and looked the ATL DLL projects that I found. But I cannot find any example like this. Is the method of accessing the members and writing more methods for them appropriate also?
*Is there any other way to access the attributes of the class?(Without using DLL functions like get_name or get_course)
*Is there any other way to assign IStudent to CStudent to access the attributes of the Student class?
P.S. : I mean sensible not semantically right with appropriate
These post really long. I hope someone patient read it
Thanks to everybody who share ideas about this post.
|
|
|
|
|
We attempt to create new instance of Internet Explorer(6.0/7.0) as a separate process.
We have tried CoCreateInstance,ShellExecute and ShDocVw.
But in all these cases,the new browser is launched as part of an existing IE process.
How do we open the new window as a separate process?
Is there some registry or meta-data settign which enables each IE instance to open as a separate process?
|
|
|
|
|
Hi all
I will going to develop a project like a server application that is one or more client applications will request the data from the database.But database may be in same machine of the server application or other one. I want my application is act as a server application between the client application and database.Now i am using visual studio 2005.So,please help me that which is the best one like ATL or .....?
thanks in advance.....
|
|
|
|
|
Are you asking for technology to prefer in this scenario ? If yes, then opt for web services.
|
|
|
|
|
yah i want to know the technology? can you send any basic tutorial for web services.Right now i know only vc++,i didn't know vc++ .net. So, please explain that should be know the .net technology while creating web service oriented application?
|
|
|
|
|
Start with this[^] article.
|
|
|
|
|
I am working on ATL DLL project. I added some classes and properties and also some classes have attributes whose type are another class. I mean in class Student there is another class' instance named Course.
When I generate DLL and access it within C# as below, I get an exception in 3rd line.
...
student.Course.Name = "CS 100";
student.Course.Name = "CS 100";
student.Course.Name = "CS 100"; //AccessViolationException
student.Course.Name = "CS 100";
...
There is no difference whether to set the same attribute or not. The code returns "System.AccessViolationException was unhandled. Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
But with the below code there is no problem. It works fine
MyDLLLibs.Course c = new MyDLLLibs.Course();
c = student.Course;
c.Name = "CS 100";
c.Name = "CS 100";
c.Name = "CS 100";
c.Name = "CS 100";
Also I want to create a Collection using std::list to send/receive list of objects to/from DLL. For example Department class has a list named Students which is another class contains Student objects. In Students class there is Add, Remove methods and Item and Count attributes. When adding elements to the Students object as shown in below code, it returns FatalExecutionEngineError at 3rd access to Students "again".
MyDLLLibs.Department d = new MyDLLLibs.Department();
MyDLLLibs.Student s1 = new MyDLLLibs.Student();
s1.Name = "Xelon";
s1.Surname = "XYZT";
...
d.Students.Add(s1);
d.Students.Add(s2);
d.Students.Add(s3); //FatalExecutionEngineError
d.Students.Add(s4);
I can't find what is the problem. Is this an initialization or memory allocation problem?
Thanks for your help
|
|
|
|
|
I have more of a design type of question.
Can anyone tell me if it is possible to :
I have a win 32 dll and a C# web service. Instead of creating a c# client, i would like to use my win 32 dll as the client. I use this dll for other things that are all file related. Is it possible for me to make the dll the client and to be able to call the c# web service and send and receive data from it? If so, does anyone have any examples of how to turn an already existing win 32 dll into a client accessing a c# web service?
|
|
|
|
|
I just replied to this in the Visual C++ forum. Please don't cross post.
led mike
|
|
|
|
|
I AM HAVING A PICULIAR PROBLEM REGARDING THE SOFTWARE COMPATABLITY WITH REFRENCE TO WIN2000 & WINXP . THE ARITHMATIC FUNCTIONS OF SUM,MEAN,MAX,MIN,STANDARD DEVIATION ARE WORKING FINE IN WIN2000 BUT ARE SHOWING SOME DATAS WRONG & SOME NULL IN XP .PLEASE SUGGEST ME SOME STEPS TO SOLVE THE ABOVE PROBLEMS.
THANKS & REGARDS,
SATYABATA NAIK
SATYABRAT NAIK
|
|
|
|
|
Hi guys,
just a quick question with printing in VB.Net. I have managed to print a form by making an image and using the BitBlt API, though I have been unsuccessful in getting the entire form if it scrolls past the size of a form.
Could someone please point me in the right direction?
Thanks in advance,
Daniel
-- modified at 1:48 Tuesday 13th March, 2007
Found a control that does what I want, though it needs a little tweaking for my purposes. I hope this also helps others looking for a similar solution:
http://www.codeproject.com/csharp/ControlPrint.asp[^]
|
|
|
|
|
Hi,
I'm creating a DLL and there is a code listing below that gets and puts an array of characters named minput. When I send English characters to the put function, there is no problem. I can get back the correct characters with get function. But when I send non-English characters (like Turkish characters ı,ç,ö,ş,ğ,ü), the function returns some strange characters.
Is there any idea why this is happening?
Thanks
PS: The project's character set is set to "Use Unicode Character Set" as default.
//Input.h
...
public:
char minput[100];
public:
STDMETHOD(get_m_input)(BSTR* pVal);
public:
STDMETHOD(put_m_input)(BSTR newVal);
...
//Input.cpp
...
STDMETHODIMP CInput::get_m_input(BSTR* pVal)
{
// TODO: Add your implementation code here
CComBSTR bstStr(this->minput);
*pVal=bstStr.Detach();
return S_OK;
}
STDMETHODIMP CInput::put_m_input(BSTR newVal)
{
// TODO: Add your implementation code here
::wcstombs(this->minput,newVal,99);
return S_OK;
}
...
|
|
|
|
|
xelontr wrote: char minput[100];
Modify this to, TCHAR minput[100]; . And make you application UNICODE enabled.
|
|
|
|
|
I changed type of the array to TCHAR and changed the put function's wcstombs to
_stprintf(minput, _T("%s"), (LPCTSTR) newVal);
and it worked. Is there any other (easy) way to change the BSTR to TCHAR? Or is this the best one?
Thanks again
|
|
|
|
|
xelontr wrote: Is there any other (easy) way to change the BSTR to TCHAR?
Consider using ConvertBSTRToString .
And does using TCHAR solved your problem ?
|
|
|
|
|
Yes, TCHAR solved the problem. Now the functions work properly.
But I can't use ConvertBSTRToString. It gives "cannot convert from 'char *' to 'TCHAR [100]'" error.
Thanks
|
|
|
|
|
xelontr wrote: ConvertBSTRToString. It gives "cannot convert from 'char *' to 'TCHAR [100]'" error.
ConvertBSTRToString returns char* , where as TCHAR is defined as wchar_t in case for UNICODE and char otherwise.
So use appropriate conversion function.
|
|
|
|
|
Hi all,
Can anyone explain to me why when IE7 is shut down my control's destructor is not called?
Thanks
Tom
I'm using: VS.NET 2003, XP SP1, ATL, IE7
Philosophy: The art of never getting beyond the concept of life.
|
|
|
|
|
What type of control it is ? I mean is it BHO ?
I remmember similar porblem(not in IE), when in client I forgot to release control.
|
|
|
|
|
Hi Prasad, thanks for the response.
My control is a windowless ActiveX control embedded in a web page.
Tom
Philosophy: The art of never getting beyond the concept of life.
|
|
|
|
|
Haven't used control anytime that way.
But, just a guess, if you needed to access control interface, then have you released it ?
|
|
|
|
|
I'll have to look into that. There might be something wrong at the core. It's an old control, not originally created by me.
Philosophy: The art of never getting beyond the concept of life.
|
|
|
|
|
Yes, it seems , control is never released.
|
|
|
|
|
Thanks I'll post if I find any thing useful.
Tom
Philosophy: The art of never getting beyond the concept of life.
|
|
|
|
|
We are creating a instance of Internet Explorer with CoCreateInstance,of type CLSCTX_LOCAL_SERVER.
Though the IE instance is successfully created ,it picks up the process id of an existing prior opened IE instance.
Is this behaviour inherent to IE?
Is ther any way to create a IE instance with its own specific process id.
|
|
|
|