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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try vbNullString ?
Farzad AkbarnejadDeveloperCommented:

use vbNullPointer for long pointers

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

Farzad AkbarnejadDeveloperCommented:

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

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sk33v3Author Commented:
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...
sk33v3Author Commented:
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&)
sk33v3Author Commented:
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
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As any) As Long

For all API reference:

~ fantasy ~
Dirk HaestProject managerCommented:
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


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
Richie_SimonettiIT OperationsCommented:
sk33v3, what is the api function/declaration that you are using (in first)?
sk33v3Author Commented:
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?
Richie_SimonettiIT OperationsCommented:
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.

sk33v3Author Commented:
Public Declare Function StartCommunication Lib "MyCom" (ByRef lpdwHandle As Long, ByVal dwPortType As Long, ByVal PortAddress As Long, lpbReserved As Long) As Long
Richie_SimonettiIT OperationsCommented:
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)
sk33v3Author Commented:
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.
Anthony PerkinsCommented:
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

sk33v3Author Commented:
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.
Anthony PerkinsCommented:
Thank you for taking care of your open questions.  However, I believe you overlooked this open question:

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

MyAPICall(LngHandle, TypeOfOption , ByVal 0&, ByVal 0&)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richie_SimonettiIT OperationsCommented:
WOW!, THE BOY is back in town!!
Richie_SimonettiIT OperationsCommented:
"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 :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.