ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Creating a Windows DLL with Visual Basic
Subject:   Is DllMain being Called?
Date:   2007-09-09 10:02:58
From:   Neounk
Response to: Is DllMain being Called?

I've added this and the entry point is indeed being changed. BUT, when I compile the dll it seems that DllMain is running before the message box in the linkers code. For example I tried this:


Option Explicit


Const DLL_PROCESS_DETACH = 0
Const DLL_PROCESS_ATTACH = 1
Const DLL_THREAD_ATTACH = 2
Const DLL_THREAD_DETACH = 3


Public Function DllMain(ByVal hInst As Long, ByVal fdwReason As Long, ByVal lpvReserved As Long) As Long


Select Case fdwReason
Case DLL_PROCESS_DETACH
Print #1, "This is a test:: Finishing!"
Close #1
' No per-process cleanup needed
Case DLL_PROCESS_ATTACH
' No per-process initialization needed
Open "test.txt" For Output As #1
Print #1, "This is a test:: Starting!" & vbCrLf
DllMain = 1
Case DLL_THREAD_ATTACH
' No per-thread initialization needed
Case DLL_THREAD_DETACH
' No per-thread cleanup needed
End Select


End Function


when compiling it makes the test file and writes to it perfectly. When i try to load the dll in my application LoadLibrary returns 0. So I checked the dll in my debugger, everything is fine until any call (for example vbaOpenFile). As soon as it enters any of these calls it crashes. removing any calls and just leaving DllMain = 1. makes it load fine.