Passing info out of a DLL

Posted on 2002-06-16
Medium Priority
Last Modified: 2010-04-01
I know next to nothing about Windows API, DirectX and vc++, but I want to pass System/DirectX information back to another language.
Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?
I have made working dll's along the lines of the following:

from test.cpp

int testint( int const *in,int in_size,int *out,int out_sz )
     int ddcheck = 1;
     *(int*)out = ddcheck;


int testfloats( int const *in,int in_size,int *out,int out_sz )
     float i = 1.234567;
    *(float*)out = i;

int teststring( int const *in,int in_size,int *out,int out_sz )
     char name[100] = "Just some text adsfhashd asflash dfkjhsadf jhaslkjfh s";


int iotest( int const *in,int in_size,int *out,int out_sz )
     int i = *(int*)in;
    *(int*)out = i;

my header file contains this type of code for each function:
extern "C"{
_declspec(dllexport) int _cdecl teststring( int const *in,int in_size,int *out,int out_sz );

Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?
For example I want to pass back the DeviceEnumeration information that is held in a struct, I also need to be able to pass back the hwnd, and more...
1) How to pass back struct information
2) How to pass back hwnd information.
3) How to pass back other non-char,non-int, non-float information.
Working source of passing DirectX info back would be a bonus!
All help greatly appreciated
Question by:cyderpunk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Accepted Solution

Roshan Davis earned 2000 total points
ID: 7082916
You call this below function with null pointer, then the function should return the size though the parameter pnSize, after that, u have to allocate that much size, then the function should return the value by that pointer. This is the normal routine for data passing.

func(BYTE* ptrByte, int *pnSize)
     if ( ptrByte )
          *pnSize = m_nLength;
          memcpy(ptrByte, m_ptrBuffer, *pnSize);

Another thing is that, you can make the structure or array into a buffer. So the calling function again it make the buffer to the structure or array.


LVL 49

Expert Comment

ID: 7083056
hi cyberpunk,
I can't parse this sentence:
>>Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?

Is it your desire to call Windows API functions from Blitz Basic (what is Blitz Basic?).  Or do you want Blitz Basic to call a C++ DLL so that *it* can call Windows API? (if so, why?)  Or do you want to write a C++ DLL to do something having to do with DirectX?  Or what?  Please advise.  Thanks!

-- Dan

Author Comment

ID: 7083424
I can create working dlls to pass some infoormation, ie floats, ints, chars, as in my source above, but i cant get structs out.
The purpose of the dll is to provide information (Directx/System) that has no equivalent command in Blitz.
Basically I dont understand the data type and how to pass them back.
>>Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?
What I  meant by that was any value returned by the function i can capture and use, and any value passed to the out( declared above) i can capture but how to i persuade vc++ to pass these (ie hwnd & DDEnum) data types to a function that must conform to the above format.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 49

Expert Comment

ID: 7084663
You need to do about what roshman suggested.  

Many paramters (such as HWND, or HANDLE) are 32-bit values -- unsigned ints.  That should be no problem.   In the case of a string, you will need to know how Bliz Basic works.  It can be quite tricky *returning* string data to Ms Visual Basic from a DLL, so you may encounter similar problems.  In general, pass in a buffer and let C++ fill it in with a null-terminated string and then figure out how BlitzBasic will handle that situation.

For a data structure such as a BITMAPINFO record, the Basic program should provide a buffer of adequate size.  The C++ program will fill that buffer.  Then the Basic program will need to be able to access the individual members of that structure.  Does Blitz Basic support a concept like "custom data types?"  If so, you can layout a custom record so that you can access the parts of the data strucure.

-- Dan
LVL 11

Expert Comment

ID: 7262356
Dear cyderpunk

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept


comment(s) as an answer.


Expert Comment

ID: 7332950
Force accepted

** Mindphaser - Community Support Moderator **

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question