Re: Sockets in a DLL, access violation

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



New information: I don't believe it is a multiple thread problem. I
added a GetCurrentThreadId, and both the case that worked and the case
that didn't gave me the same thread ID. So I am stumped at this point.
Any other ideas?

Jon Harris wrote:
Yes, I have. I initially had a problem when I wasn't doing this with assertions
in attaching handles. When I added that code, the assertions went away, but the
access violation remains. I have verified that for the function call that gives
me the access violation, AFX_MANAGE_STATE is being executed.

--
Jon Harris
SPAM blocker in place:
Remove 99 (but leave 7) to reply

"Norbert Unterberg" <nunterberg@xxxxxxxxxxxxxxxxx> wrote in message
news:u0ZybFXiGHA.3408@xxxxxxxxxxxxxxxxxxxxxxx
Jon,

Have you added this code to the beginning of all our DLL exported functions?

AFX_MANAGE_STATE(AfxGetStaticModuleState());

Norbert



Jon Harris schrieb:

I have a DLL that opens a simple UDP socket and does basic operations. My
DLL is called from a 3rd party app that I neither have control over nor
source code for. Some calls work OK, but with others I can a unhandled
exception, access violation. I've seen the exception on ReceiveFrom, SendTo,
Close, etc. and in all cases it looks like the function calls had all good
parameters.

After doing a bunch of Googling and reading, it looks like the most common
cause of this is creating the socket in one thread and accessing it from
another. (The other common problem, a bug in MSVC 6 with MFC DLL as a static
linked library, shouldn't be an issue since I have the latest service pack
(SP 6) installed.) So I am suspecting a thread problem. However, as I
mentioned above, I am in a DLL and don't have control over the calling app,
so I can't confirm the thread issue and if I could, I'm not sure how to solve
it. So my questions are: 1) is there a way to tell if my DLL code is being
called from different threads? and 2) if so, how can I write my sockets code
in such a way as to survive being called from different threads?

My set-up is MSVC 6.0 SP6, Windows 2000, MFC 4.2 as a shared DLL. Any help
is appreciated!


.



Relevant Pages

  • Re: Access Violation using CCriticalSection in DLL
    ... including the declarations of all variables involved ... precisely where does the access violation happen (it doesn't happen "in the DLL", ... When I Load a DLL (That I ... I pass the address of the log program by reference to the DLL. ...
    (microsoft.public.vc.mfc)
  • R e: Catching access violation exceptions
    ... >> exception handling support. ... >> option enables Microsoft's Structured Exception Handling in ... >> EH so that a catch will catch an access violation. ... least attempt to disable that DLL from being used the next time. ...
    (comp.lang.cpp)
  • Re: VerQueryValue() problem
    ... Do you get an access violation? ... > afterwards I query the version information of the DLL and I am running into> the problem, that VerQueryValue() fails on some systems and runs OK on> others for the same DLL. ... > My eMail-address has been changed due to spam. ...
    (microsoft.public.win2000.developer)
  • Re: Sockets in a DLL, access violation
    ... I initially had a problem when I wasn't doing this with assertions ... me the access violation, AFX_MANAGE_STATE is being executed. ... Have you added this code to the beginning of all our DLL exported functions? ... how can I write my sockets code ...
    (microsoft.public.vc.mfc)