Passing info out of a DLL

Posted on 2002-06-16
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
LVL 23

Accepted Solution

Roshan Davis earned 500 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.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

856 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