Pass an error cluster in and out of a C/C++ dll?

Hi all,
I'd like to know if it is possible to pass a LabVIEW error cluster to a C/C++ function from a dll. This would greatly help error handling in the different VIs.
I am able to access and modify the first two members of the error cluster; the error status and the error code, which are, respectively, boolean and integer. But I cannot modify the string. LabVIEW crashes completely doing so.
I first define a structure in C++ like this:
const int N = 512;
#pragma pack(push,1)
typedef struct lvcluster {
bool status;
int code;
char source[N];
} lvcluster;
#pragma pack(pop)
Then, I define a function that will access the members status, code and source:
int TestCluster(lvcluster *err)
err->code = 1;
err->status = false;
sprintf(err->source, 'Test');
I then use LabVIEW's "Call Library Function" to call this dll's function. I have set the parameter "err" to "Adapt to Type" and "Handles by Value". Trying to write characters to the source array crashes LabVIEW.
Is this possible at all? How should it be done?
Thanks!

Thanks all for the comments.
I've been looking at extcode.h where I saw the defeninition of a LStrHandle. It seems to be a pointer to pointer to "character array":
typedef struct {
int cnt; /* number of bytes that follow */
unsigned char str[1]; /* cnt bytes */
} LStr, *LStrPtr, **LStrHandle;
The "character array" is different than a C character array, see http://www.ni.com/white-paper/4877/en/#toc4
The first 4 bytes contain a signed 32 bit integer representing the number of characters. There is no NULL-termination character.
 So the error structure should be something like this (modulo the size of boolean, thanks rolfk):
const int N = 512;
#pragma pack(push,1)
typedef struct lvcluster {
bool status;
int32 code;
LStrHandle source;
} lvcluster;
#pragma pack(pop)
From there, I was able to access a LabVIEW string from C. But I am unable to modify any of it. I might be able to change the characters from an alreay allocated string, but resizing or even creating a new string crashes LabVIEW. As reported by others, manipulating these strings would require linking against labview's library to access the string manipulation functions, but this is not possible as the library must be independant of LabVIEW.
The only last possible way I can think of is to allocate a new cluster inside the DLL. Then I might be able to change the string in it, and hopefully LabVIEW would pick it up. I don't know how LabVIEW manages its memory; would it garbage collect the input cluster that is not used anymore?
Thanks for all the feedback.

Similar Messages

  • How can I pass a file refnum into and out of external c++ code? What type does it convert to in c++?

    I am trying to write external c++ code that will read a file already opened by Labview and therefore assigned a refnum. (Unfortunately, I definately can't use the standard Labview vis.) However I am not sure what c++ type to use in order to manage the refnum.
    All help and thoughts appreciated. Thanks,
    Joanna

    You could do ALL your file handling in C or C++ (MFC CFile for
    example) and pass Microsoft file handles into and out of LabVIEW
    instead of LabVIEW file references into and out of C. This may be an
    easier way to attack the problem.
    You could create a DLL in MSVC that exports a FileOpen function, a
    FileClose function and a FileRead and/or FileWrite Function and then
    call that DLL from place to place as required in your code.
    It would help us if you would explain what kind of data you are trying
    to read or write and what the application is. Is it binary data?
    text files? Do you need some special Win32 file system feature like
    file mapped memory? I guess what I am asking is what is your
    motivation for doing file handling in C or C++?
    Douglas De Clue
    LabVIEW developer
    [email protected]
    "Rolf" wrote in message news:...
    > A LabVIEW file refnum is an internal Magic Cookie to LabVIEW and there is no
    > way to directly extract the actual information assigned to that Magic
    > Cookie.
    > However the CIN Reference Manual describes one function which allows to
    > retrieve a lower level "File" handle and at least on Windows 32 bit and
    > LabVIEW
    > from version 5 up to and including 6.1 this "File" LabVIEW datatype directly
    > maps
    > to the Win32 API "FILE" Handle.
    >
    > The function to use is
    >
    > MgErr FRefNumToFD(LVRefNum refNum, File *fdp);
    >
    > It is declared in extcode.h or one of its dependant headers and exported
    > from "labview.lib"
    > all located in the cintools directory and you can link this lib also to a
    > normal DLL project.
    > However calling this DLL then from any other process than LabVIEW or a
    > LabVIEW
    > executable will not initialize the DLL anymore correctly.
    >
    > Your best option if you need to write in C(++) should be to use the LabVIEW
    > file manager
    > functions described on the External Code Manual (manual/lvexcode.pdf) on
    > this File handle.
    > If you need to use directly some Win32 API functions with it please note
    > that although currently
    > the "File" in the LabVIEW file manager functions matches the FILE in Windows
    > 32 bit API
    > functions this is an undocumented and hence unsupported feature. The next
    > LabVIEW version
    > may actually use a different datatype for its "File" parameter to the
    > LabVIEW file manager calls
    > and your use of assuming File == FILE may simply crash.
    >
    > Also operating on a file refnum in LabVIEW which has been accessed directly
    > with Win API
    > functions may result in strange behaviour such as the file read/write mark
    > not being updated as
    > you would maybe expect it.
    >
    > "Jo" wrote in message
    > news:50650000000800000016520000-1023576873000@exch​ange.ni.com...
    > > How can I pass a file refnum into and out of external c++ code? What
    > > type does it convert to in c++?
    > >
    > > I am trying to write external c++ code that will read a file already
    > > opened by Labview and therefore assigned a refnum. (Unfortunately, I
    > > definately can't use the standard Labview vis.) However I am not sure
    > > what c++ type to use in order to manage the refnum.
    > > All help and thoughts appreciated. Thanks,
    > > Joanna

  • Error Cluster Source and Explanatio​n differ

    I have a routine that unbundles the error cluster and is supposed to append the 'source' string to some status information that had occurred before that point.  I ran some tests and found that the "Source" string differs (provides less information) than what is displayed in the Explanation field of the ErrorOut Cluster.  How do I access the more verbose 'Explanation'?

    Hi Mr Bean!
    The errors are staded in several .txt files in the National Instrument library on your harddrive, search for *errors.txt and you will find a lot of them.
    You can even state your own errors if you Select Tools»Advanced»Edit Error Codes in LV.
    I created a simple VI there i use the Error Code Database.vi from the Error.llb to get the description for a specific error code.
    Regards
    /Thomas
    Attachments:
    Error_Code.vi ‏22 KB

  • Pass error cluster from labview dll to teststand

    Hello,
    I just want to pass an error cluster from a dll compiled in LV7.1 to TestStand 3.1. I never receive the contents of the LV error cluster in TS. I compiled my function with standard calling convention option, this should work. In my VI I generate only an error and pass to error output.
    LV Settings:
     TS settings:
    regards
    MB

    MB,
    please follow the info in this KB:
    http://digital.ni.com/public.nsf/allkb/22BF02003B4588808625717F003ECD67?OpenDocument
    Please note that using "By Value" will never return any values to TestStand!
    You cannot use the default error-container in TestStand to receive data from the LV error cluster if you compile the VI into a LV DLL.
    So either you choose to follow the KB or you split up the error cluster in your LV VIs to return error.occurred (boolean), error.code (numeric i32) and error.msg (LV String) .
    hope this helps,
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Multiple error cluster lines

    Hallo LabVIEWers,
    trying to make a good programming style, I implement error cluster inputs
    and outputs on each of my VIs very thoroughly.
    Now then, if I use eg the VI Server to call my VIs (call by reference node)
    I have two error cluster outputs in my data flow, one from the Call by
    reference and one from my own VI.
    Now my question: How should I handle these two flows, is there a way to or
    them together ? Should I ignore one of them ? Should I keep them seperate ?
    Wiring the CallByReference output cluster to the own VI's input doesnt't
    work because of cycle dataflow dependancies (of course)! What's a good
    LabVIEW style and what are your suggestions ??
    Thank you
    Oliver

    Under the Time&Dialog palette
    Merge Errors
    Lets you merge error I/O clusters from different functions. The function
    first looks for errors among error in 1, error in 2 and error in 3, then
    through error array in. The first error found is reported. If no errors are
    found, the function then looks for warnings and returns the first warning
    found. If no error warning is found, the function returns no error.
    Click the parameters for more information.
    If you're in LV5 you'll just have to implement a similar function.
    Oliver Friedrich wrote in message
    news:[email protected]..
    > Hallo LabVIEWers,
    >
    > trying to make a good programming style, I implement error cluster inputs
    >
    and outputs on each of my VIs very thoroughly.
    > Now then, if I use eg the VI Server to call my VIs (call by reference
    node)
    > I have two error cluster outputs in my data flow, one from the Call by
    > reference and one from my own VI.
    >
    > Now my question: How should I handle these two flows, is there a way to or
    > them together ? Should I ignore one of them ? Should I keep them seperate
    > Wiring the CallByReference output cluster to the own VI's input doesnt't
    > work because of cycle dataflow dependancies (of course)! What's a good
    > LabVIEW style and what are your suggestions ??
    >
    > Thank you
    >
    > Oliver
    >
    >

  • Stub out Error Cluster from Error Code.vi?

    When I profile my application, I find that the biggest consumer of CPU time is the Error Cluster from Error Code.vi, called from a number of locked NI libraries.  How can I stub out this .vi, replacing it with basically a pass-through?  I tried creating a project specific .vi with the same name, and when I open my project all the project and vi.lib .vis used link to it, but they all come up broken and have to be re-linked, which I can't do in the locked .vis (I matched the ins and outs and connector pattern).  I can't edit the Error Cluster...vi directly, getting a message about the .vi being used by another application even with a clean start of LV and going directly to that .vi in the library (and I would prefer to not mess with the vi.lib version anyway).  Any suggestions?  Thanks.  LV 2011.
    Matt

    If you have the LLB manager open it reserves your VI in a different appliation instance, therefore it is locked and no editing.  Simply close the LLB manager and you can whack away at that VI.
    I doubt that the shared clone setting plays much of a role here, there are some deeper issues.   A rather amusing VI in a few ways:
    In order to show the VI Title instead of the Name you Open a VI reference which is going to stick you into the root loop.  10 reentrent clones simply means 10 copies waiting in line for the root loop.  A non-reentrent version would simply have 10 copies waiting to run.  Minus the root loop issue, reentrency is the way to go, and on a desktop machine shared clones is typically quite effective.
    It can't be a slow VI, look Trim Whitespace was inlined manually to avoid a performance hit!  In a loop maybe, but really, shaving off the overhead of a single subVI?  That's optimization.
    But wait, all of that and much, much more is given right back by the use of Delete From Array to remove the first element of the Array.  Bad on so many levels.    Delete From Array is a data copy machine, and now you are doing one needlessly.  Array subset is your friend here, tells the compiler you are only reading, nothing to get excited about. Pull it outside the case structure, you are ditching the first element twice in the two branches.
    Concatenating strings in a loop, also a recipe for fun.  Often there are ways to leverage Array to Spreadsheet string for better performance, or build a string array and then concatenate at the end.  Probably not a big deal here, how big are call chains really, but if you are inlining subVIs by hand then you should really be frying the bigger fish.
    I find myself in your shoes fairly often.  Some clunker in vi.lib causes a bug or sluggish performance.  You either ditch the NI code and roll your own, or make it work on your machine but not others, or chalk it up to the cost of doing business.  I have tried on numerous occasions to suggest that all patches to vi.lib be made readily and freely available to all previous versions of LV that are compatible.  Let's say this VI got tweaked so it was a bit more performant for you, at least enough to be viable.  Then you could happily use the patched version in LV11, and if you went to a different machine you would simply make sure vi.lib was up-to-date.  These types of patches could roll out incrementally as needed, less need to cross your fingers that you won the CAR lottery with each new version of LV.  (I guess most lottery winners don't shell out $$$ to collect their "winnings" though).
    After all that what would I do here?  I would wrap that sucker inside a disable structure (provide minimal functionality, like pass through caller name, code and error instead).  Then I would check the performance again.  Now you have a data point as to whether or not it is worth it to proceed.

  • LabVIEW new "Silver" error cluster and TestStand

    I have some new VI's that use the new "Silver" style error controls and indicators.  I started calling the VI's from TestStand and noticed that the new VI's were not auto populating the TestStand error to the VI's error out.  Not sure how this mechanism works but it doesn't work with the default "Silver" controls.  I think it is name based case sensitive and I just have to rename the "Error Out" cluster to be lower case "error out".

    Paul -
    Can you confirm that the problem you're describing is that because the name of the Silver error cluster is "Error Out", when you configure a LabVIEW step to call a VI that has the Silver error cluster wired to the connect pane, TestStand does not automatically assign Step.Result.Error to that parameter? If so, we have reproduced this behavior and yes, you are correct that it is due to case sensitivity. We have taken note of this in order to fix the problem in a future version of TestStand.
    I also just wanted to confirm that the problem is not that the error information is not correctly passed from LabVIEW to TestStand, when you assign Step.Result.Error to a Silver error cluster parameter.
    Please let me know.
    Manooch H.
    National Instruments

  • 2TB Ext. Hard Drive is corrupted?, error code -50 and then error code -35 when i try to empty out my trash

    okay so a few days ago i received and email for one of my colleagues to do some final editing to a music video. the folder contained 2 videos a rough chops and the main which was about 2-3GB which i dragged on to my external hard drive . and at the time i was trying to install a trial version of parallel lines and me being a newbie to the software i didn't know i need windows installments for it to run lol but yeah... so i was just getting frustrated with the software i kept installing it uninstalling it and then i was thinking my the problem might be because my MacHD space is low (less then 40GBs on my MacHD), so.. i installed it on my hard drive where all my important files are (I'm a graphic designer and do light video editing) video projects and many photoshop projects form 2007 and logs and just a bunch of important files in my hard drive. so because i was so frustrated with the software i wasn't thinking and i installed it on my external 2TB hard drive. and when i realized parallel wasn't working i gave up, uninstalled the program form the hard drive and for some reason when i did that and i tried opening the video my friend had email to me and for some reason it did load up but a few seconds maybe about 10sec in the video is froze and closed my media app (VLC) and when i tried opening other video files it would freeze every few minutes but those specific files i had drag in last were not playing after at least 5 secs and eventually didn't open at all so i restart my computer login and now i get scared i see that my MacBook Pro isn't reading my external hard drive so i search threw forums... i unplug from the wall plug my external hard drive back in my computer and it loaded up but when i opened my external hard drive all my files had that plank white paper icon on my folders (because i have everything organized but subject when you open then drive folder. so... i go in to my projects and nothing, i open my edited photos and nothing... my hart feels like its about to drop and i keep opening files and there is nothing in them, but in "get info" of my drive it shows that there is filled so i go to "disk utility"... i "verify disk" passes ..."repair disk" doesn't past.... i look it up in forums... so i reboot my computer and go to the safe recovery menu. go threw the same ting "disk utility"... verify, pass... repair, pass... so now i feel relieved. i login files in the ext. hard drive load up i tried again to open the files and same thing happens... so now I'm thinking its the files i drag the files to the trash and try to empty and its gone i reboot the computer and my drive didn't load up so i tried unplugin it and back in... drive comes up i notice theres trash.. i tried emptying it and i get the error code -50. and no files are popping up on my external drive and i try to repair/unmount disk and the verify disk doesn't pass and when i click repair disk it doesn't past and another error code pops up -35.... so i felt my drive alone for a few days and yesterday i go the files deleted from the trash and now I'm not getting any codes but when i try to unmount.verify/repair the disk. keeps letting my tits need to be repaired so i click the repair button another error unable to unmount volume to repair...
    what do i do? my files still don't show up. and I'm very sorry for the long paragraph but i have to be detailed for you to understand my situation

    Read this.

  • Receiving Error "A Number Is Out of Range" in Acrobat 8.1.2 and 7.0

    I create mapbooks for the county I work at using ESRI's ArcMap ArcEditor. Once the book is done I convert it to PDF so that officers, fire fighters, etc. can open it on their laptops. Recently I started receiving the error "A Number is Out of Range" when I finish combining the PDF files into a binder. The error persists anytime I change pages and I have to click OK several times before it goes away. This becomes a problem for emergency management when their trying to search a road, plus it is also very annoying. Does anyone know how to get around this? It didn't use to do this. I thought maybe it was the fonts I was using, so I changed most of them to Arial and Times New Roman, yet it still persists, but seems slightly better. I cannot find anything on Adobes website about A Number is Out of Range. Also, I am using Acrobat Professional 8.1.2 and have also tried Professional 7.0. I'm running Windows XP. I have also tried reverting back to old versions of ArcMap and also the mapbook software MapLogic, but nothing helps. Any help would greatly be appreciated.

    I'm getting this error also, and I don't think it's a font issue. Here's my situation.
    I created a 144-page manual in Adobe FrameMaker 8.0 using the same template and fonts that I have used in several other large manuals. I saved the manual as a PDF using Acrobat 3D 8.0, and is get the mind-numbingly vague error "A number is out of range." I didn't get this error in previous versions of this manual, nor do I get this error with the other manuals on which I am currently working. I had inserted some EPS technical drawings, so I opened all of them in Illustrator CS3 and Created Outlines for any text that appeared in the illustrations.
    After two days of replacing all of the fonts, optomizing PDFs, and distilling, distilling, and distilling again, I was not able to get rid of this message using Acrobat. I finally pulled out my MacBook Pro, opened the PDF manual using Preview, saved the PDF under a different name (no need to apply a Quartz filter), and (abracadabra!) the vague error message is gone!
    Fonts may be one cause of the annoyingly vague "A number is out of range" error, but they are not the only one. And with such informative error messages as that, I doubt I'll ever know what is really wrong with my PDF.
    Cheers!
    Michael Opsteegh

  • Is there a way of passing a mixed cluster of numbers and booleans to teststand

    Hi,
    I have a labview VI that contains an output cluster containing both numeric and boolean results and would like to pass this to Teststand. At the moment I have coverted all my boolean results to  '1/0'  so that I can create a numeric array and can quite easily pass this to Teststand (using multiple numeric limit test). 
    Is there a way to pass mixed results to Teststand and write in the limits (example PASS and GT 5V) or do I have to stick with what I have?
    Chris

    Which test step type to use depends on what you have to analyze - a boolean condition? String? Number(s)? I can't tell you because I don't know what's in your cluster. If you click on the plus sign next to the parameter name "output cluster" you will see all paramters and their types, which are passed from the VI to TestStand.
    You can either create a variable for the whole cluster, or you can assign all or just some values from within the cluster to variables.
    The name of the variable (Locals.xxxxxxx... or FileGlobals.xxxxx...) ist what you type in the value field. You can also choose the variable from the expression browser by clicking on the f(x) button.
    Are you new to TestStand, do you know how to work with variables in TS?
    Maybe the attached picture gives you an example, there I am assigning the values from VI output "VoltageOutputArray" to the TS variable locals.VoltageMeasurement.
    This variable ist used again on the tab "Data Source" as the Data Source Expression.
    Regards,
    gedi
    Attachments:
    stepsettings.jpg ‏89 KB

  • Trying to update my ipod but i get the error message network timed out.  I've already uninstalled and reinstalled the latest version of itunes. I also do not have software update in settings on the ipod. How do i get the ipod to update?

    trying to update my ipod but i get the error message network timed out.  I've already uninstalled and reinstalled the latest version of itunes. I also do not have software update in settings on the ipod. How do i get the ipod to update?

    Try the manual method specified here:
    iDevice Troubleshooting 101 :: iPhone, iPad, iPod touch

  • Help! I have recently updated LR5 and before doing so I was able to email files to clients! (Very Convenient) Now my problem is I have not been able to get pass this error message reading "failed to send" which gives no further detail about what to do to

    Help! I have recently updated LR5 and before doing so I was able to email files to clients! (Very Convenient) Now my problem is I have not been able to get pass this error message reading "failed to send" which gives no further detail about what to do to rectify the situation. Someone please guide me through this! Thanks in advance!

    Did this ever get resolved, as I am having the same issue.  Trying to learn LR5 AFTER a decade using Aperture.   I was able to set up a validated account but when I try to send an e-mail or photo I get the simple " Failed to Send " message.   Using latest version of Mac OS X.

  • My iPod Is disable and it's said connect to iTunes but it won't let me connect . It keep saying pass code error.

    My iPod saids disable please connect to iTunes . When I plug it in it said pass code error and it won't let me go in iTunes ! Help please .

    iOS: Unable to update or restore

  • HT202159 Tried restarting download from the "Purchases" tab but the app comes out with "an error ocurred " message and I the button next to it is grey without any text or action. Please help, cannot dowload bad piggies game

    Tried restarting download from the "Purchases" tab but the app comes out with "an error ocurred " message and I the button next to it is grey without any text or action. Please help, cannot dowload bad piggies game

    Hi aaronvilla,
    Sorry to hear you are having issues with your iTunes Store purchase.   The following information should help you with this:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
    To report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase, follow these steps:
    Find the email receipt for your purchase.
    Click Report a Problem under the app that is having the issue.
    When prompted, enter the Apple ID and password you used to purchase the item, then click Report a Problem.
    Click Report a Problem next to the item you are having an issue with.
    From the Choose Problem dropdown menu, choose the appropriate issue.
    Follow the onscreen instructions and—if prompted—type a description of the problem into the text field.
    Click Submit to have your issue reviewed.
    Hope this helps ....
    - Judy

  • TS3694 pls help my iphone 4 was on activation "required". i jailbroke it then it worked but some of the applications were crashing down,won't open. i tried a lot of tutorials and then error message 3194 came out. stucked in recovery mode,itunes logo. pls

    pls help my iphone 4 was on activation "required". i jailbroke it then it worked but some of the applications were crashing down,won't open. i tried a lot of tutorials and then error message 3194 came out. stucked in recovery mode,and then i use snowbreeze and then it worked!!!! but another problem came, i turned off my iphone then i switched it on again then it stucked in apple logo,.after doing some thing again 1604, 1600 bla bla bla came out..pls help me fix my iphone.

    no help for jailbroken phones here-it's not allowed. good luck.

Maybe you are looking for

  • How can I get my built in camera on my 15" retina display Macbook Pro to work with online websites, such as chatroulette, etc.?

    I just purchased a 15" Macbook Pro with retina display. How can I get my webcam to be compatable online with websites such as chatroulette, etc? I have the latest version of flash, my system is updated, and my camera works on photo booth, skype, etc.

  • Problem in Supplier Invoice - Item Category

    Hello all, When trying to create an Invoice, the system returns the following error: [Item category 40100 not allowed in accounting transaction 0300/0001] Where/How can I solve this problem? Kind Regards, Miguel

  • BPM Wait step!

    Friends, I have BPM which has the FOR-EACH Block in it. After the first message processed I have to wait for atleast 5 seconds to process the next message in FOR-EACH Block. The default BPM wait step has minimum of 1 Minute. Is there any other way we

  • Brain:485 Posting Period 0FISCPER3

    Hi. All, After execution of my query on the portal I am getting this error : Brain:485 Posting Period 0FISCPER3. Not sure what it means. Please help to understand this and provide me some solution. what I have done is: I just executed in RSRT also bu

  • Apple Update software clobbers reinstall of iTunes

    Hi all, I am having an issue the has escalated over the last day or so with iTunes. I attempted the upgrade to 7.3 and began to encounter an error in which the Apple Software Update screen would open in iTunes and I would get the Visual C++ Runtime e