Link to home
Start Free TrialLog in
Avatar of sk33v3
sk33v3

asked on

API Call Requires Null

How do you send a null value to an API call in VB? Its got to be the same as if I were to type null in C++....  whenever I use VBnull it doesn't work, whenever I set a variant value to null that does work either.... Thanks
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try vbNullString ?
Hi,

use vbNullPointer for long pointers
define

const NULL_STR_POINTER = &0;
and use for pointer to string that must be null.

-FA
Sorry

use vbNullString for string type. define NULL_LNG_PTR = &0 and use for long type.

-FA
Avatar of sk33v3
sk33v3

ASKER

when I try to declare that null_lng_ptr it adds an O

Public Const NULL_LNG_PTR = &O0
The O means that the number is octal number. If you need a hexadesimal number write &H0. I'm not sure if it really matters whether you use octal or hexadesimal number...
Avatar of sk33v3

ASKER

neither of the 2 work right, it doesn't return what the C++ equivalent of Null for a long is.
u can send api null as &0. like following;

SendMessage(<hwnd>, <message_code>, <wparam>, ByVal 0&)
Avatar of sk33v3

ASKER

what goes in the hwnd, message_code and wparam?
Normally, we use &0 as null for long.
For example, the SendMessage(me.hwnd, BN_CLICKED, 0&, 0&)
The hwnd can be any window handler for example

dim hwnd as object
hwnd = findwindow("classname", "windowcaption")

If the above cannot work, then try to change long to any like
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As Long) As Long
to
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As any) As Long

For all API reference:
http://www.mentalis.org/

Thanks,
~ fantasy ~
You can also try vbNull
try with the null character ' '. In  VB use the returned value from Chr$(0) to create this null character
If your API declaration is for a string parameter and you want to pass null, I'm surprised that vbNullString doesn't do the job.

Another method is to rewrite the declare statement. e.g. FindWindow could be rewritten from

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

to

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

The second would allow for use of the 0& long constant just about everyone else has mentioned.

Dim hWnd As Long
hWnd = FindWindow (0&, "whatever")
Sorry, that sould've been ByVal

hWnd = FindWindow (ByVal 0&, "whatever")
Your API function (SendMessage I take it) will work with 0& for long and vbNullString for string, as said. It's probably the message you're sending that's failing. Check the return value of the function to see.
Yes it might be the message is failing
sk33v3, what is the api function/declaration that you are using (in first)?
Avatar of sk33v3

ASKER

Well I can't give you the Actual DLL Call but I can make a mock up of what it looks like.

MyAPICall(LngHandle, TypeOfOption , NULL_LNG_PTR, NULL_LNG_PTR)

Any Ideas?
I don't want dll, just what declaration are you using.
Is it a standard dll that comes with Microsoft products?, if no, do you know if that dll accept callings from VB?, just remember that for dlls used by VB, they have to follow _stdcall calling convention.

Avatar of sk33v3

ASKER

Public Declare Function StartCommunication Lib "MyCom" (ByRef lpdwHandle As Long, ByVal dwPortType As Long, ByVal PortAddress As Long, lpbReserved As Long) As Long
All parameters appears to just longs, so passing 0& as last parameter should be enought if it doesn't waits for a pointer to a function (like EnumChildWindows api in example)
Avatar of sk33v3

ASKER

well I was told the error I was getting from it was because I wasn't passing Null to it properly, All the examples they have are for C++ only and they use the null constant....
Could you post the C++ example used? You might need to pass a pointer to a buffered string which is null-terminated. Blind guess, however. Have no clue on how the function is supposed to handle it's parameters.
Please maintain your many old open questions:

1 09/19/2003 500 RealBasic  Unlocked Macintosh Programming
2 09/26/2003 500 Power point(PPT) to Quicktime(mov) Conve...  Unlocked Microsoft Office
3 10/12/2003 500 Print Screen  Unlocked Visual Basic
4 01/23/2003 50 Network Trouble shooting utility  Unlocked Networking
5 08/27/2003 250 PHP With IIS?  Unlocked Internet Information Server
6 10/06/2003 500 RB, What is wrong with this?  Unlocked Macintosh Programming
7 10/07/2003 250 Windows App to Mac App. Registry?  Unlocked Macintosh Programming

Thanks,
Anthony
Avatar of sk33v3

ASKER

Well what we ended up doing was making the Interface into the component in C++ and referencing it from VB.... That fixed it. I am going to request that this question be deleted. Thanks.
Thank you for taking care of your open questions.  However, I believe you overlooked this open question:
https://www.experts-exchange.com/questions/20758795/RB-What-is-wrong-with-this.html

In order to close this question, see the following:
Request a refund because you answered your own question (Refund/PAQ) https://www.experts-exchange.com/help/closing.jsp#4
Request a refund because no one answered your question (Delete) https://www.experts-exchange.com/help/closing.jsp#5

Thanks,
Anthony
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WOW!, THE BOY is back in town!!
Hi!
:)
"Mr. Ark, ...welcome back, we...missed you"
Hello Richie and all experts! Finally I've defend my PhD degree on wednesday and now I'm back :)