[3DX Coding] Sample code to generate Apt source

Hello to the whole community. Could someone provide me a sample code to generate the apt source of a manufacturing program in 3D experience please, considering that I retrieved the manufacturing program (in Vb, C or C++). In V5 I don't have a problem but in 3D experience (20X), when I use the "initFileGenerator" function, I have a crash when I generate an apt for the second time (it looks like a stream remains open). I then have to generate the apt in 3dx and it works again for once in my program.
Here is the error message:
System.Runtime.InteropServices.COMException: 'Unrecoverable failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
Thank you for any help you can give me.

Best regards.