Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

610 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