Jump to content

DLL for Excel 2000 in Assembly language


Recommended Posts

Hi all!

I'm writing a dynamic link library in assembly language making floating-point computations for VBA (MS Excel 2000). I'm using MASM32 package under Windows 98 SE. I have written and debugged all necessary functions and almost all of them work correctly, with the exception of the main function (it uses all other functions from this DLL). When I call it from the Visual Basic Editor in Excel, it succeeds several times (once, twice, even eleven times) but finally fails. Excel crashes (Err.Number = -2147417848, Err.Description = "Method 'MyMethod' of object 'MyObject' failed") and Windows reports the error in the vbe6.dll (not in my dll):

Program EXCEL caused an invalid page fault in module VBE6.DLL at 0167:65009f43.

Registers:

EAX=00002584 CS=0167 EIP=65009f43 EFLGS=00010202

EBX=00000000 SS=016f ESP=0062ed8c EBP=0062efd0

ECX=65225ba0 DS=016f ESI=00000007 FS=2f1f

EDX=0000d000 ES=016f EDI=00000000 GS=0000

Bytes at CS:EIP:

8b 00 8b 40 04 c2 04 00 33 c0 eb f9 b8 a0 5b 22

Stack dump:

65009f64 65225ba0 6500ada0 65225ba0 0041767c 00000000 00000000 00001045 00000001 0062edb4 00000000 00000001 0062efe4 0062edc4 00000000 00000001

(Corresponding excerpt from the vbe6.dll disassembly

65009F35 fn_65009F35:

65009F35 8B442404 mov eax,[esp+4]

65009F39 8B400C mov eax,[eax+0Ch]

65009F3C 85C0 test eax,eax

65009F3E 740B jz loc_65009F4B

65009F40 8B400C mov eax,[eax+0Ch]

65009F43 8B00 mov eax,[eax] ; <--

65009F45 8B4004 mov eax,[eax+4]

65009F48 loc_65009F48:

65009F48 C20400 ret 4

)

or

Program EXCEL caused an invalid page fault in module VBE6.DLL at 0167:65012c3f.

Registers:

EAX=00000009 CS=0167 EIP=65012c3f EFLGS=00010206

EBX=0062e884 SS=016f ESP=0062f2e8 EBP=0062f338

ECX=00000000 DS=016f ESI=0062e884 FS=2cf7

EDX=016e4718 ES=016f EDI=00417350 GS=0000

Bytes at CS:EIP:

8b 08 e8 10 aa 06 00 8b 40 14 c2 04 00 8b 44 24

Stack dump:

650112c0 0062e884 650112f4 0062e884 00417350 00402c78 00000000 650a0c7b 00000000 650a0c11 016e4718 016e4718 00417350 00000000 00000000 0166403c

(Corresponding excerpt from the vbe6.dll disassembly

65012C38 fn_65012C38:

65012C38 8B442404 mov eax,[esp+4]

65012C3C 8B400C mov eax,[eax+0Ch]

65012C3F 8B08 mov ecx,[eax] ; <--

65012C41 E810AA0600 call fn_6507D656

65012C46 8B4014 mov eax,[eax+14h]

65012C49 C20400 ret 4

65012C4C 8B442404 mov eax,[esp+4]

65012C50 8B4C2408 mov ecx,[esp+8]

65012C54 8B809C000000 mov eax,[eax+9Ch]

65012C5A C1F81F sar eax,1Fh

65012C5D 8901 mov [ecx],eax

65012C5F 33C0 xor eax,eax

65012C61 C20800 ret 8

)

or

Program EXCEL caused an invalid page fault in module VBE6.DLL at 0167:65009f45.

Registers:

EAX=0f10e0c1 CS=0167 EIP=65009f45 EFLGS=00010206

EBX=0062eb0a SS=016f ESP=0062e9d0 EBP=0062ea20

ECX=65225ba0 DS=016f ESI=ffff8001 FS=0f2f

EDX=00010008 ES=016f EDI=00000001 GS=0000

Bytes at CS:EIP:

8b 40 04 c2 04 00 33 c0 eb f9 b8 a0 5b 22 65 8b

Stack dump:

65009f64 65225ba0 65137006 301b5d78 01140674 00000000 0062ea40 300fdda2 00000003 00000000 0062eb0a 00000000 0b480167 0062ea0c 16bf016f 8a1e1547

(Corresponding excerpt from the vbe6.dll disassembly

65009F35 fn_65009F35:

65009F35 8B442404 mov eax,[esp+4]

65009F39 8B400C mov eax,[eax+0Ch]

65009F3C 85C0 test eax,eax

65009F3E 740B jz loc_65009F4B

65009F40 8B400C mov eax,[eax+0Ch]

65009F43 8B00 mov eax,[eax]

65009F45 8B4004 mov eax,[eax+4] ; <--

65009F48 loc_65009F48:

65009F48 C20400 ret 4

)

I have tried Visual Basic 6.0 Professional 6.0 to get rid of the error in vbe6.dll (VB6 doesn't use it), but the situation remains the same: though there is no vbe6.dll loaded when I'm running Visual Basic exe-file, the similar error happens in kernel32.dll:

Program VB6 caused an invalid page fault in module KERNEL32.DLL at 0167:bff7a4b2.

Registers:

EAX=00000000 CS=0167 EIP=bff7a4b2 EFLGS=00010206

EBX=00000000 SS=016f ESP=007feab0 EBP=007feac0

ECX=005d0008 DS=016f ESI=005d0000 FS=3777

EDX=00000010 ES=016f EDI=005d000c GS=0000

Bytes at CS:EIP:

8b 03 25 fc ff ff 0f 3b 45 0c 0f 83 81 00 00 00

Stack dump:

00000001 0fc00001 00000000 00000000 007fead4 bff88dc4 005d0000 00000010 00000000 007feb24 7ff214f0 005d0000 00000000 0000000c 0fa916c7 7ffce00c

(Here is the corresponding excerpt from the kernel32.dll disassembly:

BFF7A4B2 loc_BFF7A4B2:

BFF7A4B2 8B03 mov eax,[ebx] ; <--

BFF7A4B4 25FCFFFF0F and eax,0FFFFFFCh

BFF7A4B9 3B450C cmp eax,[ebp+0Ch]

BFF7A4BC 0F8381000000 jnb loc_BFF7A543

BFF7A4C2 8B5B04 mov ebx,[ebx+4]

BFF7A4C5 3BFB cmp edi,ebx

BFF7A4C7 75E9 jnz loc_BFF7A4B2

)

Dll function is called from the method in class module (I changed their names to MyMethod and MyObject above), it takes a lot of parameters and works (if succeded)

for quite a long time (some seconds).

I've already tried reinstalling Microsoft Office 2000 and Windows 98 SE. Search with Google hasn't been very fruitful yet.

I'd like to complete this work which has already taken some months and combine the power of floating-point instructions with the comfortable interface of Microsoft

Office and abilities of Visual Basic for Applications. So I'm not going to change none of the two programming languages I'm using.

Can anyone give me some advices or related links?

Thanks in advance.

Edited by AleXnderRT
Link to comment
Share on other sites


Did you build a COM DLL or just a DLL with exported functions ?

Maybe it's a register preservation problem or memory freed to soon or a bad pointer or a mistake in COM implementation.

Without source code it gonna be hard to help but if I were you I wouldn't search outside your DLL, the problem is in there.

I'm a MASM coder so if you don't mind posting the source, I'll look at it.

Link to comment
Share on other sites

I build a simple DLL with exported functions.

I carefully saved every register that any procedure is using. I did it in the right form, i. e.:

Some_proc proc SomeParameter:DWORD

LOCAL SomeVariable:DWORD

push ebx

push ecx

push esi

push edi

;some code

pop edi

pop esi

pop ecx

pop ebx

ret

Some_proc endp

Should it be pusha and popa? What if the procedure doesn't use registers at all?

I think I have the register preservation problem earlier when some procedures of the DLL were crashing and Windows were reporting errors in my DLL and VBE6.DLL. But since I'd started saving registers like this all of procedures became working with the exception of the main procedure. Main procedure (I mean it's role, not the DLLEntry procedure) calls other DLL procedures thousands of times.

I tried to put calls to MessageBox at the beginning and at the end of the main procedure and between calls to other procedures. Then I reduced passed parameters so that every procedure was called only once from the main procedure. All messages were shown but after the last Excel crashed (i. e., on exit from the DLL function it was calling).

If you give me the explanation of "memory freed too soon" I'll try to manage the problem on my own.

The whole library is a bit large. What if I send you it along with the VBA modules and comments in both as the private message (or give me your e-mail at pageusr@rambler.ru, I will use it only to send you my code, nothing else:). That's because I don't want the code to be available to everybody in the Internet (at least now). And you are the only member who want to see it. Aren't here somebody else do?

Link to comment
Share on other sites

AleXnderRT,

For your information...

1) ECX is not a register that need to be preserved

2) Memory freed to soon is when you use memory allocation API like HeapAlloc and use the pointer after a call to HeapFree

Did you tried running your VBA module in debug mode and see where it crash ? That way it could be easier to know which DLL function cause the problem.

Look your PM for my e-mail address.

Regards

Link to comment
Share on other sites

And you are the only member who want to see it. Aren't here somebody else do?

MASM programming is not very popular and there is only very few members here that still use assembly. Don't be surprised that there is no rush for helping you. Moreover, programming is not the main objective of this board. For a real assembly board you should go to The MASM forum

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...