|
|
Thanks for this - but my object is not STA but MTA... I checked this in the registry... the threading model is apartment!
|
|
|
|
|
Do you have access to the code for the COM classes? - or are you building around it with no clue as to how it works? In MTA the COM object performs the synchronization.
A cynic is a man who, when he smells flowers, looks around for a coffin. -H.L. Mencken
|
|
|
|
|
Yes I have the source code for the COM object : I programed it as well - that does not obligatory mean I have a clue though...
|
|
|
|
|
Geez OK well this is my somewhat limited take on it. My understanding is that in STA it acts like a UI - it responds to input, while in the MTA it is internally handled - Are you sure you need MTA?
STA can handle multiple threads it is just that there one to one relationship between the apartments and the threads. In MTA the threads are sort of like in a mixed bag that you are required to do some extra coding for. I am not sure what the exact problem if you are always coming up the same thread - can you clip some code that shows the getting of the thread / thread pointer?
You might be interested in this article:
COM Apartments and .NET Threads[^]
-- modified at 15:18 Friday 8th September, 2006
A cynic is a man who, when he smells flowers, looks around for a coffin. -H.L. Mencken
|
|
|
|
|
Not sure if I need MTA or STA, what I need is that calls from different internet sessions have their own thread when they arrive in the COM object... It seems crazy that the same thread would be resued within the COM Object. Well well...
I did read the article aearlier today googling about... it seems like the ASP.net code is ints own thread pool but not within the COM object...
Ahhhhhh... I am going mad!
Thanks for your help, brother !
|
|
|
|
|
What is wrong with the following code? (it's homework, but I couldn't figure out anything)
#include <assert.h>
class Object
{
public:
Object () : pAlive (new bool (true)) {}
~Object () { assert (*pAlive); * pAlive = false; delete pAlive; }
private:
bool * pAlive;
}; // Object
int main()
{
Object x1, x2;
x1 = x2;
return 0;
}
Jon
|
|
|
|
|
There will be a memory leak. x1 and x2 both declare a boolean variable on the heap. Since Object doesn't have a copy-constructor/assignment operator, it uses the implicit one that will copy the value of the pointer from x2 to x1. Thus, the data that x1's original pointer was pointing to is still allocated, but has no way of getting access to it to delete it.
Worse, if the line *pAlive = false; is not there, the code will actually cause memory corruption since x1 and x2 will both have pointers to the same boolean variable and will both try to delete it.
NOTE: In general, I wouldn't answer homework questions this thoroughly ... but I'm feeling generous today.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
jon_80 wrote:
x1 = x2;<pre>
after this line (x1.pAlive == x2.pAlive)
once destructor on the first one has been called, pAlive of otherone is a dangling pointer(location to which it points is no longer valid). hence the assertion fails.
OT: learn to use a debugger.
|
|
|
|
|
If this is not a homework problem get rid of the pointers, the new and the delete as there is no good reason to dynamically allocate and use a 32 bit value in this way.
John
|
|
|
|
|
John M. Drescher wrote: If this is not a homework problem
He did state that it was a homework problem ...
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi everyone,
I want to use m_hDC in CImage class but when i write m_image.m_hDC; i get this error:
error C2248: 'ATL::CImage::m_hDC' : cannot access private member declared in class 'ATL::CImage'
is it possible to use private members in this class
Thanks
|
|
|
|
|
You should use .Attach in the CImage class.
Chris
|
|
|
|
|
Hi Chris,
I want to know how can I use from private members in CImage class
Thanks
|
|
|
|
|
CImage::m_hDC is read only so therefore after you use the Attach function you can use CImage::m_hDC to see what is attached.
Chris
|
|
|
|
|
Hello
I have a problem which is difficult to explain, because I do not understand why it occurs.
Here is what I do:
* create a named pipe (server end) with CreateNamedPipe
* create a named pipe (client end) with CreateFile and SetNamedPipeHandleState
I use the same buffer size in both ends of the pipe
server end:
I specify PIPE_NOWAIT as 3rd argument to CreateNamedPipe
I specify PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE as 2nd argument to CreateNamedPipe
client end:
in CreateFile I set GENERIC_READ | GENERIC_WRITE
and set pipe mode to PIPE_NOWAIT | PIPE_READMODE_BYTE using SetNamedPipeHandleState
Then I sync. the 2 processes, when the client has connected to the server, I intend to write a series of bytes to the client end of the pipe using WriteFile
The code I am describing is working as a dream on 2 different windows XP machines, and 3 different windows 2000 machines, as long as I write no more than buffer_size bytes per write.
but on one particular windows 2000 server, WriteFile returns 1 (which means success), but bytes written is set to 0.
the client can read all day if he wants and still only get 0 bytes.
After a lot of debugging and testing, I figured out, on this particular windows 2000 server, if I write buffer_size - 24 bytes, the WriteFile returns 1 (success) and bytesWritten = the number of bytes I requested.
but it always has to be 24 bytes less than the actual buffer I specified in the CreateNamedPipe function. I do not understand why.
Does anyone have an explanation or theory for me?
Cheers.
|
|
|
|
|
what if you change the pipe mode to MESSAGE ? That way, each read and write happens as a unit, and you don't have to read specific numbers of bytes.
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
I am using both message modes and byte modes, the reason I also use byte mode is that sometimes I need to send data to the child processes, which I don't know the size of at compile time.
I've implemented my own mechanism for splitting up the data and pushing it onto the pipe in chunks.
But the problem is when I request a buffer size for the pipe, I am unable to utilize the full buffer. In my case, there is a overhead of 24 bytes that I can't use each write operation.
I am just wondering if anyone else has experienced anything similar.
|
|
|
|
|
On Server and Client side i create an SPN like this :
DsMakeSpn("ncacn_ip_tcp","some.valid.DNS",NULL,0,NULL,&pcSpnLength,pszSpn);
On the Server i register Authentication Information with
RpcServerRegisterAuthInfo((unsigned char*)pszSpn,RPC_C_AUTHN_GSS_KERBEROS,NULL,NULL);
and a Security Callback Dummy Function that just return RPC_S_OK.
On the Client side i call
RpcBindingSetAuthInfo(BindingHandle,(unsigned char*)pszSpn,RPC_C_AUTHN_LEVEL_CALL,
RPC_C_AUTHN_GSS_KERBEROS,NULL,
RPC_C_AUTHN_GSS_KERBEROS);
I Get "RPC Error 5 : Access Denied" from inside the client Stub-Function. This site
http://support.microsoft.com/?scid=kb%3Ben-us%3B838191&x=13&y=11
says, that the Error is incorrectly mapped and meight also be "Error 1717 : Interface Unknown". That doesnt help me either. So can anyone help me ?
I tried fetching Extended Error Information, but there doesn't seem to be any generated. When i deactivate Interface Restriction in the Group Policy Editor and leave all the Authentication
Stuff out, it works. But i don't want to go that way, it has to be possible.
|
|
|
|
|
Hi,
Maybe this might help you ...
<a href="http://www.codeguru.com/cpp/com-tech/atl/general/article.php/c11627">http:
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
I'm sorry, but i couldn't find any usefull Information there. The Article was about COM+ but i use Microsoft RPC, wich is one level below. I browse the Web fpr some Sample or Tutorial now for 3 days, but it just seems, no one uses it. And Microsoft really did a crappy job on the Documentation...
|
|
|
|
|
Sorry I couldn't help but, concerning the RPC and the crappy job of the documentation ....
What do you expect, Microsoft couldn't steal it from someone.
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Why can't the derived class access protected members from its base class?
#include <iostream>
using namespace std;
class CEmployee
{
protected:
float m_HourlyRate;
float m_HoursWorked;
};
// class CEmployee //forward declaration
class CAccountant : protected CEmployee
{
public:
void CalcSalary(CEmployee &emp)
{
emp.m_HourlyRate = 50;
emp.m_HoursWorked = 1;
};
};
void main ()
{
CAccountant joe;
}
Error:
Test.cpp(17): error C2248: cannot access protected member declared in class 'CEmployee'
Also, in the code above I was trying to use a forward declaration so that I could declare CEmployee after CAccountant, but the following compilation error was displayed:
error C2504: 'CEmployee' : base class undefined
Does this mean that forward declarations cannot be done on classes that might need to be inherited?
Jon
|
|
|
|
|
jon_80 wrote: void CalcSalary(CEmployee &emp)
{
emp.m_HourlyRate = 50;
emp.m_HoursWorked = 1;
};
protected access us for derived classes only. i.e. derived class can access protected member in base class.
But externally its acts as private.
In above case m_HourlyRate and m_HoursWorked of base class can be accessed from CAccountant . But you are trying to access those member of using class instance. Which is not allowed.
jon_80 wrote: Does this mean that forward declarations cannot be done on classes that might need to be inherited?
yes.
|
|
|
|
|
I think you want a virtual method instead:
class CEmployee
{
public:
virtual void CalcSalary( void ){}
protected:
float m_HourlyRate;
float m_HoursWorked;
};
class CAccountant : protected CEmployee
{
public:
void CalcSalary( void )
{
m_HourlyRate = 50.0;
m_HoursWorked = 1.0;
};
};
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|