Issue 111526 - vbNullString does not work well for dll call, such as FindWindowA("",vbNullString)
Summary: vbNullString does not work well for dll call, such as FindWindowA("",vbNullSt...
Status: ACCEPTED
Alias: None
Product: App Dev
Classification: Unclassified
Component: vba (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact: noel.power
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-11 09:23 UTC by lihuiibm
Modified: 2017-05-20 11:27 UTC (History)
2 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Test document for this issue (25.50 KB, text/plain)
2010-05-11 09:32 UTC, lihuiibm
no flags Details
Patch for this issue (12.48 KB, text/plain)
2010-05-13 10:59 UTC, lihuiibm
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description lihuiibm 2010-05-11 09:23:46 UTC
vbNullString does not work well in dll call ,such as
FindWindowA("",vbNullString). Following VBA code(Open the Windows calc app first):

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton1_Click()
    Dim hWnd As Long
    hWnd = FindWindow("SciCalc", vbNullString)
    MsgBox hWnd
End Sub

According to the definition of Windows API 'FindWindowA', the second parameter:
lpszWindowName Points to a null-terminated string that specifies the window name
(the window's title). If lpWindowName is NULL, all window names match. 
We input vbNullString as the second parameter, in Excel, I think it is regarded
as NULL, so FindWindow(...) can find the window, but in OOo, it can't find the
window.
Comment 1 lihuiibm 2010-05-11 09:32:57 UTC
Created attachment 69408 [details]
Test document for this issue
Comment 2 lihuiibm 2010-05-13 10:59:41 UTC
Created attachment 69441 [details]
Patch for this issue
Comment 3 lihuiibm 2010-05-13 11:05:12 UTC
According to the definition of Windows API 'FindWindowA':
The second parameter: lpszWindowName Points to a null-terminated string that
specifies the window name (the window's title). If lpWindowName is NULL, all
window names match. 
In the test case, we want to find the window that the class name is "SciCalc"
and match all window names:
winwnd = FindWindow("SciCalc", vbNullString)
In OOo, vbNullString is defined as a empty String, it's different with NULL. So
it can find the correct window.

I check if the parameter is vbNullString or not, if yes, in dllmgr.cxx, I put a 
NULL into the parameters stack, please see the changes in
SbiDllMrg::CreateStack(...).

Please see detail in patch.diff
Comment 4 noel.power 2010-05-13 11:55:20 UTC
well I have to say, hats off for the getting stuck into the compiler code etc.
But... unfortunately I find it hard to believe that we need to go to such
lengths ( e.g. such a large patch ) to solve this problem :-/ I think ( erm I
hope ) there should be an easier solution. The real problem to address as I see
it is that 

a) vbNullString is incorrectly represented as an empty string instead of a null
string
b) possibly openoffice basic can't distinguish between a null ( e.g.
uninitialised string ) and an empty ( e.g assigned to "" ) string, don't know if
indeed that is the case need to look at that [*]
c) dllmgr.cxx additionally needs to be aware of the difference between a null
and empty string and needs to pass NULL for a NULL string ( at least for that
api but probably this is a general rule )

VBA most certainly does ( as we can see from the example ) distinguish between
the null and empty strings. Of course to make things more interesting it seems (
I just played a little with it in excel ) a null string mostly behaves exactly
like an empty string most of the time, e.g. if you compare a null and empty
string in basic they evalate equal ;-)
Comment 5 noel.power 2010-05-13 12:27:23 UTC
unfortunately I am begining to think it might be necessary to go to the lengths
that you went to as there seems there no easy way that empty / null strings can
be disambiguated :-( I wonder though is the patch set up so that unitialised
Strings are treaded as Null 

e.g.

dim foo as string
Wnd = FindWindow("SciCalc", foo )

should yield the same result as 
hWnd = FindWindow("SciCalc", vbNullString)

Andreas though is the expert here on all things basic compiler related and I
give over to his wisdom
Comment 6 ab 2010-05-28 10:36:25 UTC
STARTED
Comment 7 Rob Weir 2013-03-11 15:05:52 UTC
I'm adding this comment to all open issues with Issue Type == PATCH.  We have 220 such issues, many of them quite old.  I apologize for that.  

We need your help in prioritizing which patches should be integrated into our next release, Apache OpenOffice 4.0.

If you have submitted a patch and think it is applicable for AOO 4.0, please respond with a comment to let us know.

On the other hand, if the patch is no longer relevant, please let us know that as well.

If you have any general questions or want to discuss this further, please send a note to our dev mailing list:  dev@openoffice.apache.org

Thanks!

-Rob
Comment 8 Marcus 2017-05-20 11:27:32 UTC
Reset assigne to the default "issues@openoffice.apache.org".