General programming: dlls


#1

sorry this isn’t juce related, but you guys are a trustworthy bunch.

i’ve got to write my own midi handling classes (just for messages and output) for a uni project. it’s going well, and i’ve not encountered any problems so far.

however, some of the other people in my group are using VB to write their app, so i’m putting the midi functions into a dll. for the most part, i’m okay with that, but i’m a little confused about how i’m going to get the port access done. in my own C++ version, i’ll just get a Midi_Output object that i created when i opened the device, and use that to send the messages. I’m not sure how i go about doing such a thing so that a VB coder can use it.

How would it be possible for me to do such a thing? My only thought at the moment is that i can have a class to hold all the midi output ports that may be open, and have an exposed ‘initialise’ funtion to create it. All my other functions would then make use of that instance, like a singleton. Is that even possible? From what i gather, i can only really just expose static/global functions, and can’t return my custom objects. Am i right here? I’m fairly new to this lark.


#2

sorry, what a knob, this should be in the windows forum :oops:


#3

terrifying to hear that they’re teaching VB in universities…

No idea about how to integrate with VB, but it probably can’t access a c++ class, so I imagine you’d need to write a set of flat functions as the interface.


#4

good lord.

most Unis teach Java but let students use what they like for projects. I had muppets on my project team too. I took one look at the spec, rattled off a solution in a day, then left the pricks to get on with documenting and project plans and such like. I got failed for non-attendance! but got condoned (passed without resitting) for threatening to shop the entire school for plagiarising my code (other project)

woah! OT!! sorry.

your talking really really evil COM/ActiveX programming dude. all visual basic really is is the scripting of these COM objects. it’s fucking horrible ugly messy verbose code for these fuckers my friend!

I did one before we became a juce house. a guitar fretboard visual control. I could script it in VB VERY easily if I wanted.

absolute nightmare.

might be easier for you as your object is not visual?

start with the C++ ActiveX wizard in VS and take it from there.


#5

well, what i’m planning is to just create a class to wrap any MIDI_OutputPort objects that may be opened in, and have some global functions to get the count, name, or send a message from one (by index, naturally). From what i’ve been reading this afternoon it seems like I’ll be okay to just create a global instance of this type within the dll, and have the access functions use that.

I’m personally not going anywhere near VB. I can’t stand it, and don’t see the point in using it! It’s like learning to build a house with just bread… it might be easy enough to make a little house, but when you want to make a real house your bread-skillz will be a bit crumby! oh dear!


#6

Indeed, truly horrifying that people are still using VB, but if you want to write a dll for it, make sure to wrap your dll declerations in C constructs and make the dll listing file (whatever its called, I’m tired). If they will only ever need one instance of your midi thing loaded at a time, then just put global init functions and such and expose them, simple in that regard, make sure to properly cleanup on dll unload as well as an exposed function as people may not always call a cleanup function you make (personal experience). If you need to support multiple instances, then I’d say make a vector (or hashmap if you want to pass things by string for ease of vb programming peoples use) to store your objects in and just on init functions make a new one and pass back the index it is stored in, and pass in that index for every function input so they know what to act on, just make sure to check that they don’t call invalid indices… Overall, working with vb is not an easy method, I’ve gotten things to work using a basic c constructed dll like that.


#7