Microsoft KB Archive/281913

= BUG: Referencing Different Type Libraries May Render an Executable Platform Dependent =

Article ID: 281913

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition

-



This article was previously published under Q281913



SYMPTOMS
After compiling a Visual Basic project that references more than one type library on one platform (such as a Microsoft Windows 2000-based computer), the resulting binary fails to run on other platforms (such as Microsoft Windows NT 4-, Microsoft Windows 95-, Microsoft Windows 98-, and Microsoft Windows ME-based computers) and gets an Access Violation (AV).



CAUSE
The Visual Basic compiler is case sensitive when it is reading entries for dllname in type libraries. As a result, if a project references two or more type libraries and the dllname entry for the same DLL is spelled in different cases in different libraries, such as dllname(&quot;kernel32.dll&quot;) in library A, and dllname(&quot;KERNEL32.DLL&quot;) in library B, the compiler generates two import sections for the same DLL and renders the binary platform dependent.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Set up a Windows 2000-based computer and a Windows NT 4-based computer, both with the latest service packs. Also install Visual Basic and Visual C++ 6.0 with Service Pack 5 on both computers.  On the Windows 2000-based computer, copy-and-paste the following Interface Description Language (IDL) code into Notepad, and save it as lcase.idl. Compile it with MIDL.EXE, midl lcase.idl. The resulting type library is named lcase.tlb. [ uuid(D618AA4D-814A-47a2-9AC1-DDE18EDF1C54), version(1.0), helpstring(&quot;Lower case test&quot;) ] library lcasetest {   [      dllname(&quot;kernel32.dll&quot;), version(1.0), helpstring(&quot;Sleep function exported by kernel32.dll&quot;) ]   module lcasetest { [           entry(&quot;Sleep&quot;), helpstring(&quot;sleep - lcase test.&quot;) ]       void _stdcall Sleep([in] long dwMS); }; };                     As in step 1, build ucase.tlb with the following IDL code: [ uuid(3F215C63-D0AD-4980-93F2-5DDF850061E4), version(1.0), helpstring(&quot;Upper case test&quot;) ] library ucasetest {   [      dllname(&quot;KERNEL32.DLL&quot;), version(1.0), helpstring(&quot;Sleep function exported by kernel32.dll&quot;) ]   module lcasetest { [           entry(&quot;Sleep&quot;), helpstring(&quot;sleep - ucase test.&quot;) ]       void _stdcall Sleep([in] long dwMS); }; };                    Create a Visual Basic Standard EXE project. Form1 is created by default. On the Project menu, click to select References. In the References dialog box, browse to lcase.tlb and ucase.tlb, select both libraries, and then click OK.  Add the following code to Form1: Private Sub Form_Load lcasetest.Sleep 1 ucasetest.Sleep 1 End Sub </li> On the File menu, click to Save the project, and then select Make Project1.exe to compile the project.</li> Run the executable, Project1.exe, and note that the form appears with no errors.</li> Copy Project1.exe to the Windows NT 4-based computer and run it. Note that an Access Violation occurs.</li> Copy and compile the same project on the Windows NT 4-based computer and run it on both the Windows NT 4- and Windows 2000-based computers. Note that it fails on the Windows 2000-based computer.</li></ol>

Additional query words: tlbpatch

Keywords: kbbug kbnofix kbcompiler KB281913

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.